Friday, 11 May 2012

How to run a script requiring sudo without needing a password

To run a script that has a sudo command in it, without needing to enter a password whenever the script is executed, add an entry in sudoers.
First, open sudoers using visudo:
 sudo visudo  

Then add the following line to the bottom of the file:
 <user> ALL=NOPASSWD: <absolute_path_to_script_file>  

Where <user> is the user running the script, and <absolute_path_to_script_file> is...self explanatory :). Though I've found that the script needs to be placed in /usr/bin/ to for the entry in sudoers to be effective.

Save the changes to the file, and log in and out to enact the change. Now, when you sudo script, there will be no prompt for a password.

No comments:

Post a Comment

Please leave a comment if you find this blog helpful or interesting! I'd love to hear from you!