0

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 :)

2
  • 3
    Are you sure giving daemon full rights to run php as root is sensible?
    – Cian
    Aug 31, 2009 at 14:21
  • Cian: Ya, that too, I just wasn't in the mood to go there ;-) Aug 31, 2009 at 14:27

2 Answers 2

3

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 :-)

2
  • That's "sudo visudo..." Aug 31, 2009 at 16:41
  • Dennis: "as root or with sudo:" Sep 1, 2009 at 11:22
0

Literally:

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

Personally I'd recommend Kyle Brandt's solution.

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

2
  • You're probably going to want a "sudo" in there somewhere. Aug 31, 2009 at 16:40
  • Dennis: It would just be: bash -c "echo '....' >> /etc/sudoers" Aug 31, 2009 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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