How to avoid being prompted for a password by sudo? [duplicate]
Well, the only thing I can think of is
echo 'password' | sudo -S command
The -S
flag makes sudo
read the password from the standard input. As explained in man sudo
:
-S, --stdin
Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. The password must be followed by a newline character.
So, to run ls
with sudo
privileges, you would do
echo 'password' | sudo -S ls
Note that this will produce an error if your sudo
access token is active, if you don't need to enter your password because you've already done so recently. To get around that, you could use -k
to reset the access token:
echo 'password' | sudo -kS ls
I don't know of any way of getting you into an actual root shell (like su
or sudo -i
) do. This might be enough for what you need though.
In terminal run the visudo
command to edit the sudoers file:
sudo visudo
and add the following line to the sudoers list
username ALL = NOPASSWD : ALL
Note: Replace username with your real UserName in above line.