2

I usually have to login in 20 to 50 times daily as a super user, typing the long password again and again..

i have just created a simple bash script

#!/bin/bash

sudo -s
echo password

./test

output root@localhost: password when i execute it, it works like charm... but it shows my password on the screen.....

do some one have any other best solution...... for this small problem.......

i hope this is not all the solution in security standard...... can we have any other solution with out exposing my password.....

forum.test17
  • 2,119
  • 6
  • 30
  • 62
  • You know, showing your password on-screen is the least of your problems if you have a shell script that automatically sudoes. Hopefully it's owned by your user and not executable (or readable...) by any group. – Damon Nov 04 '11 at 21:40
  • 2
    you could just set up sudo to not require a password – evil otto Nov 04 '11 at 21:50

5 Answers5

4

You can pipe the echo'd password into a command. Try something like this:

echo myPassword | sudo -S 

You can see come more info on this here.

Question is, do you REALLY want your password in a shell script file? (just emphasizing that its a terrible idea)

Community
  • 1
  • 1
SuperTron
  • 4,203
  • 6
  • 35
  • 62
1

just change ownership of the script to root & set SUID-Bit in user the permissions

chmod u=rws g+x o+x script123

the script will run as root for every user

1

Is there a reason that you can't sudo su - to just become the root user instead of prepending all of your commands with sudo blah?

Mike
  • 7,994
  • 5
  • 35
  • 44
0

simple solution is to use key base authentication Use ssh-copy-id instead following from this tutorial which is secure

forum.test17
  • 2,119
  • 6
  • 30
  • 62
0

You can configure sudo to require a password only every so many minutes. The default is 5 minutes. Read the sudoers man page and scroll down to this:

    timestamp_timeout
               Number of minutes that can elapse before sudo will ask
               for a passwd again.  The timeout may include a
               fractional component if minute granularity is
               insufficient, for example 2.5.  The default is 5.  Set
               this to 0 to always prompt for a password.  If set to a
               value less than 0 the user's timestamp will never
               expire.  This can be used to allow users to create or
               delete their own timestamps via sudo -v and sudo -k
               respectively.
Jens
  • 69,818
  • 15
  • 125
  • 179