1

I've searched half a day for the answer to this, with no luck. Any assistance will be appreciated.

I have a PHP script that modifies the crontab, loads a new cron job, removes some etc. The script works fine except that it says permission denied, so it can't write to the crontab.

I've determined that it might be the user trying to access the file that causes permission to be denied. Now I'm not an expert with users and groups (or Linux in general). So could someone please explain to me how I can enable access to the crontab for the linux user 'running' the website?

2
  • 1
    Do you want to edit crontab of the user the php script runs under, or crontab of another user? Have you tried editing crontab manually as the user php runs as? Jun 5, 2014 at 7:22
  • I want to edit the crontab of the user the php script runs under. I've tried, but it says permission denied.
    – Bird87 ZA
    Jun 5, 2014 at 8:33

1 Answer 1

3

If you add this line to your sudoers file (use visudo to edit it):

phpuser   ALL = (wwwuser) NOPASSWD: crontab -u wwwuser

then your script will be able to run the command

sudo -u wwwuser crontab -u wwwuser

and pipe in the new contents of the crontab.

4
  • As stated, not really experienced with linux so sorry if this question is a bit stupid. Is phpuser and wwwuser predefined users? The actual account hosting the site running the script is deltabec.
    – Bird87 ZA
    Jun 5, 2014 at 8:50
  • Sorry, I should have been more explicit. phpuser and wwwuser are placeholders for your actual usernames. So replace phpuser with the name of the user running the PHP script, and wwwuser with name of the user running the website.
    – Flup
    Jun 5, 2014 at 8:52
  • so in this case both would be deltabec?
    – Bird87 ZA
    Jun 5, 2014 at 9:09
  • It's working now. Thanks a million for the assistance.
    – Bird87 ZA
    Jun 5, 2014 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .