I would like to run sudo with my password as parameter so that I can use it for a script. I tried
sudo -S mypassword execute_command
but without any success. Any suggestions?
The -S (stdin) option allow the sudo command to read password from a standard input instead of a terminal device. If you want to store the password in a file you can use the cat command instead of echo like the following example.
In all cases, you must know the root password in advance before sudo can be configured to commands without a password. You might have sudo access and grant another user account passwordless access for commands.
The -S switch makes sudo read the password from STDIN. This means you can do
echo mypassword | sudo -S command
to pass the password to sudo
However, the suggestions by others that do not involve passing the password as part of a command such as checking if the user is root are probably much better ideas for security reasons
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With