CopyDisable

Friday, 16 August 2013

Running sudo without password

 

I was writing a script which needs a normal user (part of sudo group) to stop and start one Ubuntu Service using service command. But problem was that if I need to run service command using sudo, I had to type the password of that normal user. This was killing the automation of the script. The way was to edit the /etc/sudoers configuration file.

I am showing the steps for a normal user stgsync

Step 1: Add the user to sudo group
usermod -a -G sudo stgsync

Step2: Now edit the /etc/sudoers file using the visudo command

Step3: Add the following line

%stgsync ALL=(ALL) NOPASSWD: /usr/sbin/service

This line will allow stgsync user to run service command without entering password.

For the details of this sudoers module and writing sudoers policy statements visit this page:

http://www.sudo.ws/sudoers.man.html

Step4: Save and exit from visudo

That’s it Smile, now the stgsync user can run service command without password:

e.g.
sudo service mysql stop
will not ask for password