Question

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.....

Was it helpful?

Solution

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.

OTHER TIPS

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)

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?

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top