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/thescript.sh

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/thescript.sh

Many thanks,
Ross

link|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
feedback

2 Answers

The sudoers entry dave ALL=NOPASSWD: /home/dave/thescript.sh lets dave execute sudo /home/dave/thescript.sh 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/thescript.sh 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.

link|improve this answer
feedback

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

You are not however running thescript.sh 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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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