4

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

evachristine
  • 2,613

1 Answers1

3

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.

Ramesh
  • 39,297