8

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 '13 at 12:46
9
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 '13 at 14:17
  • Good summary, lots of questions recently that involve visudo. – nerdwaller Apr 5 '13 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... – Lev Lukomsky May 31 '17 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.