I need to run something as sudo without a password, so I used visudo and added this to my sudoers file.

MYUSERNAME ALL = NOPASSWD: /path/to/my/program

I tried it out then

$ sudo /path/to/my/program
[sudo] password for MYUSERNAME:

Why does it ask for a password? How do i run commands from the root in a non-root account without asking for a password?

Best Answer


You have another entry in the sudoers file, typically located at /etc/sudoers , which also matches your user. The NOPASSWD rule needs to be after that one in order for it to take precedence.

Having done that, sudo will prompt for a password normally for all commands except /path/to/my/program , which it will always let you run without asking for your password.