Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to be able to restart apache under OS X Lion without entering a password. I tried placing this in /etc/sudoers:

<User> ALL= NOPASSWD: /usr/sbin/apachectl

But when I execute apachectl graceful I get an error message:

This operation requires root.

What do I have to do, in order to get this working?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You still need to sudo, otherwise you are executing the command as your user by default. The difference is that it doesn't require you to enter the password.

sudo apachectl graceful

Remember that, for changes in visudo to be applied, you need to quit the editor. It's not enough to save, since the changes are initially applied to a temporary file only.


You can always define an alias or function in your shell, like the following:

alias apachectl='sudo apachectl'

Store it in your personal shell configuration file (e.g. ~/.bash_profile) to persist.

share|improve this answer
    
Thanks, that's it! –  Till Jan 23 '12 at 13:12

Your Answer

 
discard

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.