Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

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
USERHERE@notebook:~/foo$

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

share|improve this question

marked as duplicate by Gilles, slm, jasonwryan, Anthon, Zelda Apr 24 at 15:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

1 Answer 1

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.

Testing

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.

share|improve this answer

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