I want to add a user to the sudoers file so that it can only start, stop and restart a particular service.

I am using Debian and can access the sudoers file using sudo visudo, I am stumped now though on how to set up this one user to be limited to one service.

  • This should probably be moved to unix & linux stackexchange site. I flagged it to get moved.
    – slm
    Apr 5, 2013 at 12:46

1 Answer 1

root@megatron# visudo

Append following line (where megatron is your hostname)

jakenoble megatron=/etc/init.d/httpd start, /etc/init.d/httpd stop,/etc/init.d/httpd restart, /sbin/services httpd restart

Save and close the file. You have to type following command:

jakenoble@megatron$ sudo /etc/init.d/httpd restart

You must list the full command you want someone to run for visudo to allow it.

For example, given the line in /etc/sudoers

 %users  localhost=/sbin/shutdown -r now

Users can only RESTART (-r) the machine, they cannot HALT (-h) it.

  • That makes sense, I will try it
    – Jake N
    Apr 5, 2013 at 14:17
  • Good summary, lots of questions recently that involve visudo.
    – nerdwaller
    Apr 5, 2013 at 15:00
  • I wish sudoers had possibility to add several commands in one line like jakenoble megatron=/etc/init.d/httpd {start,stop,restart}. It would decrease amount of duplication... May 31, 2017 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .