I am running some scripts as part of pre/post deploy using DeployHQ, I need to be able to call the script on one line and for there to be no feedback from the terminal so I want to pass the password into the sudo command (instead of sudo asking for the password at the time of use)
I am trying to get sudo
to work with stdin
by doing something like;
echo my_password | sudo -S chown -R my_user:www-data /srv/www/my_site/public_html/
But what is getting returned is;
[sudo] password for my_user:
Sorry, try again.
[sudo] password for my_user:
sudo: 1 incorrect password attempt
The password in question is correct and when the command is ran without -S
and the user is prompted for the password is works.
Could someone point out what I am doing wrong?
Just to clarify - I want there to still be a password, just one that I can pass in.
I'm not sure what is wrong
However, if you want to run sudo without being prompted for a password, you can do so by editing the sudo configuration file. To do this use the command
visudo
The default file has lots of examples so just search for
NOPASSWD
and you should find an example to get you startedfrom the sudo manual:
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character. This means you should end password with \n
EDIT: I did a couple of test, and honestly in my test system your syntax works correctly. ( echo mypass | sudo -S .... )
2nd EDIT: Try with the following syntax:
echo -e "mypass\n" | sudo -S command