Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 want my user 'dave' to be able to run a bash script without entering a password, so the script can run with crontab? For all other activities I'd like this user to be required to enter a password (as default). I know this can be accomplished via visudo, but I'm unable to get it to work. Wrong syntax maybe?

My Visudo Entry:

dave    ALL=(ALL) ALL
dave    ALL=NOPASSWD: /home/dave/

This works in the command line, I can execute it without entering a password. But the cron is returning [sudo] password for dave:

My crontab for user 'dave' is:

0 * * * * /home/dave/

Many thanks,

share|improve this question
doesn't the crontab mention sudo? – Gilles Aug 9 '10 at 10:15
@Gilles: The cron tab doesn't. But thescript.shcontains a line with sudo... – Ross Aug 9 '10 at 10:17

The sudoers entry dave ALL=NOPASSWD: /home/dave/ lets dave execute sudo /home/dave/ without entering a password. It doesn't say anything about using sudo from that script; sudo doesn't care about what script, if any, invoked it.

If the whole script should run as root, then invoke it with sudo /home/dave/ in the crontab. But then, why not simply put the script in root's crontab?

Otherwise, if the script contains a line sudo /path/to/mycommand arguments, then put dave ALL=NOPASSWD: /path/to/mycommand arguments in the sudoers file. This will apply no matter where dave runs mycommand from.

share|improve this answer

Your entry above allows dave to run /home/dave/ via sudo without entering a password.

You are not however running via sudo.

You will have to add a similar entry for the command that the script is trying to run via sudo to your sudoers file e.g.

dave ALL=NOPASSWD: /path/to/special/command
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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