Mac – passwordless sudo apachectl

apache-http-servermacosx lionsudosudoers

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?

Best Answer

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.

Related Question