How to Create CRON Jobs that Require SUDO Permissions
I've created a basic script to automate my updates and free up some space.
You've reinvented the unattended-upgrades service.
But the problem is, I can't designate jobs that require SUDO into my regular user's CRONTAB.
Well, you can – just add sudo
to the command.
However, since cron cannot prompt you for the password, you need to designate those commands to be passwordless through /etc/sudoers
. This line would allow cron to sudo
your script:
rubaiat ALL=(root) NOPASSWD: /home/rubaiat/bin/sys-maintainer.sh
(Note: in sudoers, the last match wins. So make sure to add such exceptions at the end of /etc/sudoers, or in any case below the generic "ALL=(ALL) ALL" lines.)