Run sudo in script without password

To run a script where sudo needed but you don’t want the terminal to ask you about the password:

  1. Open a terminal and write: sudo visudo
  2. At the end of the file write: username ALL = NOPASSWD: /path/to/script/script.sh. I.e: foo = NOPASSWD: /home/foo/Desktop/script.sh
  3. In the script, when needed sudo, write: sudo -s. I.e, to open a gnome terminal with iotop, which needs sudo: sudo -s gnome-terminal -e iotop
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s