Linux – Fix Sudoers NOPASSWD Not Working for Specified Commands

linuxsudosystemctlsystemdUbuntu

I have the following entries in the sudoers file:

christian ALL=(root)NOPASSWD: /usr/sbin/shutdown
christian ALL=(root)NOPASSWD: /usr/bin/systemctl start mc

When running sudo shutdown -h now or sudo systemctl start mc, I still have to enter the password, even though I've set the NOPASSWD option for these commands. I am not sure why, because as far as I've read, this should be the correct syntax for it.

As far as I know I have to use an absolute path in the sudoers file, but I call it without. That might be the issue, but how do I make sudo workable with that then?

I'm using Ubuntu 20.04.6 LTS. What am I missing?

Best Answer

NOPASSWD: comes before the command, not after the users. Try adding a space before NOPASSWD: and maybe removing the space after.