Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For one specific user I want to be able to restart Apache. This user does have sudo privileges and I could run sudo /etc/init.d/apache2 reload, but I want to include this restart script in a git post-receive hook. So this would prompt for the password and fail. So the question is: what is the proper way to allow this user to restart apache, without requiring sudo? I want to restrict option to only restarting Apache, and only this particular user.

share|improve this question
up vote 6 down vote accepted

You should consider using sudo with the NOPASSWD config.

See man 5 sudoers


Host_Alias     LOCAL=
user_foobar    LOCAL=NOPASSWD: /etc/init.d/apache2
share|improve this answer
You should consider NOPASSWD extremely carefully, though. – Shadur Mar 19 '12 at 8:53
Sure, don't use that for all commands. Never something like LOCAL=NOPASSWD: /bin/bash – Gilles Quenot Mar 19 '12 at 13:25
Works as a charm, thanks! – please delete me Mar 29 '12 at 22:55
U're welcome ;) – Gilles Quenot Mar 30 '12 at 0:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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