6

I've noticed that crontab -e and sudo crontab -e seem to edit separate files. How do these two commands differ, and in what circumstances should each be used?

  • 1
    Arguably user neither but as an admin drop a file in /etc/crond.d or in the relevant /etc/cron.[hourly |daily |weekly |monthly] directory – HBruijn Nov 28 '16 at 21:32
15

crontab -e edits the crontab for the current user, so any commands contained within will be ran as the user who's crontab you are editing. sudo crontab -e will edit the root users crontab, and so the commands within will be run as root.

| improve this answer | |
5

To add on to cduffin, use the minimum permissions rule when running your cronjob. If the job can effectively be run as a regular user, have the job run as them. If the cronjob requires escalated privileges, add the job as the root user.

To be super security conscious, you can figure out what root level commands need run and set the regular user up in the /etc/sudoers file to be allowed to run that single command... Example:


Defaults:johndoe !requiretty
johndoe ALL=NOPASSWD:/usr/bin/tail /var/log/yum.log*
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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