my sudoers file:

cat /etc/sudoers
USERHERE ALL = NOPASSWD: /bin/cp /home/USERHERE/foo/in.csv /home/anotheruser/in.csv

it looks OK too:

USERHERE@notebook:~/foo$ sudo -l
Matching Defaults entries for USERHERE on this host:
    env_reset, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User a may run the following commands on this host:
    (root) NOPASSWD: /bin/cp /home/USERHERE/foo/in.csv /home/anotheruser/in.csv
    (ALL : ALL) ALL

but when I try it prompts for password, why?

USERHERE@notebook:~$ sudo /bin/cp /home/USERHERE/foo/in.csv /home/anotheruser/in.csv
[sudo] password for USERHERE:

Using Ubuntu 12.04

  • Did you use visudo? the line in my /etc/sudoers reads %wheel ALL=(ALL) NOPASSWD: ALL – eyoung100 Apr 23 '14 at 20:41

Edit your sudoers file using visudo to look like this.

USERHERE ALL= (root) NOPASSWD: /bin/cp /home/USERHERE/foo/in.csv /home/anotheruser/in.csv

It will not ask for the password. If you need more information you can check the answer here.


I did the following in my machine. First as root user, issued visudo command to edit the sudoers file. Then, I added the below entry to permit user ramesh to issue network restart command.

ramesh ALL = (root) NOPASSWD: /etc/init.d/network restart

After that, I did su ramesh to login as that user. Now, I issued the command /etc/init.d/network restart and it did not prompt me for password.

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