Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I’m have a bash script that I run in /etc/crontab on Linux

$ uname -a
Linux 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

The bash script contains a line

sudo shutdown -r 5

However, when the cron job runs (as a user named “myuser”), the machine is never rebooted and I instead find this in the logs

[sudo] password for myuser:

What do I need to do to give this user the ability to reboot from cron? It’s not an option to run this script as another user.

share|improve this question
up vote 0 down vote accepted

You need a line in /etc/sudoers that reads:

myuser ALL = NOPASSWD:  /sbin/shutdown

The NOPASSWD part tells sudo to let myuser run the shutdown command with providing a password.

To add such a line to /etc/sudoers, run (as root):

sudoedit /etc/sudoers

sudoedit will scan your updated version of the file for errors before installing it. Consequently, this is safer than editing the file directly.

share|improve this answer

You must log in to answer this question.

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