Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

How do I add the following to the sudoers file in RHEL5?

daemon ALL=(ALL) NOPASSWD: /usr/local/bin/php /var/www/batch.php

Thanks :)

share|improve this question
Are you sure giving daemon full rights to run php as root is sensible? – Cian Aug 31 '09 at 14:21
Cian: Ya, that too, I just wasn't in the mood to go there ;-) – Kyle Brandt Aug 31 '09 at 14:27

Use the visudo command for safe editing of the sudoers file, as root or with sudo:

visudo -f /etc/sudoers

If you don't know vi, you can use whatever editor you want by setting the EDITOR environment variable (assuming $VISUAL is not set), for example as root:

export EDITOR=/bin/nano
visudo -f /etc/sudoers

Although, if you don't know vi basics, maybe you shouldn't be editing your sudoers file :-)

share|improve this answer
That's "sudo visudo..." – Dennis Williamson Aug 31 '09 at 16:41
Dennis: "as root or with sudo:" – Kyle Brandt Sep 1 '09 at 11:22


sudo echo 'daemon ALL=(ALL) NOPASSWD: /usr/local/bin/php /var/www/batch.php' >> /etc/sudoers

Personally I'd recommend Kyle Brandt's solution.

[Edit] I've added sudo to the example as per Dennis Williamson's suggestion.

share|improve this answer
You're probably going to want a "sudo" in there somewhere. – Dennis Williamson Aug 31 '09 at 16:40
Dennis: It would just be: bash -c "echo '....' >> /etc/sudoers" – Kyle Brandt Aug 31 '09 at 17:53

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.