Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 have been trying to specify a script that I would like to run without being prompted for a password. After a number of google and stack searches and a number of different syntax changes, I still cannot get it to work. One peculiar thing is that when typing sudo visudo nano is opened to edit the file. I never specified nano as the editor, but I may have first edited the file with nano. Would that make nano the default editor? If so, could that cause problems. Thanks for the help.

Here is my sudoers file.

# This file MUST be edited with the 'visudo' command as root.
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
# See the man page for details on how to write a sudoers file.
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:$

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL) ALL
pat     ALL=NOPASSWD: /home/pat/

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
share|improve this question
So, why exactly do you think that it doesn't work? – mikewhatever Jan 11 '14 at 20:57
When running ./ while in my home directory, I am prompted for a password. – Pat Herrod Jan 11 '14 at 21:46
How about sudo ./ – mikewhatever Jan 11 '14 at 21:59
Yeah, that works, but the purpose is to have a script with su pat -c ".... The problem is that script cant run with this code unless a user is there to input a password. – Pat Herrod Jan 12 '14 at 0:50

Based on your comments:

Realize that su, unless run from as root, requires you to provide the password of the user to su to. The reason sudo ./ works is, you are running as root! (sudo defaults to root if you don't give it a -u switch.

So if you want the script to be able to su to another user it must be run as root (don't do this).

Why not just use "sudo -u pat" within the script, instead of "su pat -c"?

share|improve this answer

The default editor of visudo is nano, no problem.

1) You will need to make some changes at your line

pat     ALL=NOPASSWD: /home/pat/

It should contain the name of the computer and a space before and after the "=":

username computername = NOPASSWD: /path/to/script

Something like this:

pat patcomputer = NOPASSWD: /home/pat/

2) The script should be owned by root. Run this at terminal:

sudo chown root:root /home/pat/  

3) Set the right permissions:

sudo chmod 705 /home/pat/  

4) Enjoy!

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.