Ubuntu – Adding root privileges to a bash script


I am in need of adding root privileges to a bash script which uses sudo; so that whenever we run the script from the terminal; irrespective of the fact that the user is root or not it should not prompt for password. Please help! Doing Run Bash Script as Root did not help.

Best Answer

The best solution would be use visudo (this tool was made for that and will avoid the exposition of root password), I suggest you to dig what are going wrong with that.

As a workaround, you can run this:

echo <password> | sudo -S some-script

(start the command with a space so it won't be saved in bash history).