If you don't want to enter password manually you use -A
option of sudo
-A, --askpass
Normally, if sudo requires a password, it will read it from the user's
terminal. If the -A (askpass) option is specified, a (possibly graphi‐
cal) helper program is executed to read the user's password and output
the password to the standard output. If the SUDO_ASKPASS environment
variable is set, it specifies the path to the helper program.
How to use it?
make a file which will contain your password (unencrypted):
cat .pass
#!/bin/bash
echo password
Now set it permissions to only executable by only you:
chmod u=x,go= .pass
now the actual usage
SUDO_ASKPASS="~/.pass" sudo -A <command>
This way you can run any command as root without entering password
I wouldn't recommend you to store your password unencrypted on your computer, it is very unsafe.
sudo
. Have you considered just using backup tools that provide bare-metal restore? – Chris Davies Apr 30 '16 at 20:37recovery tool
. – Pavan Apr 30 '16 at 20:38sudo
to avoid requiring a password (read up on theNOPASSWD
attribute). But if you're in a recovery zone then I don't see how you would have the modified configuration file necessary for this to happen - you'd need to be root to change the configuration file, in which case you might as well run the entire script as root and avoidsudo
entirely. – Chris Davies Apr 30 '16 at 20:43echo password | sudo ./recover.sh
– Pavan Apr 30 '16 at 20:47id
command to see which uid is running your code) – Chris Davies May 01 '16 at 18:47