visudo cannot get around systemctl

Chris asked:

I’ve given my user root permission to run systemcl via visudo.

# visudo
XXXXXX ALL=NOPASSWD: /bin/systemctl restart shiny-server.service

After logging out and back in, I run the command:

$ /bin/systemctl restart shiny-server.service

And get:

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'shiny-server.service'.
Authenticating as: XXXXXXX

I’m seeing things on line talking about polkit but I’m not sure if that also needs to be configured along with visudo. What’s required here to prevent a password from being required to run the command as a specified user?

My answer:

You set up sudo to allow you to run a command without a password, but you didn’t actually run the command with sudo!

To fix the problem, run the command with sudo.

sudo /bin/systemctl restart shiny-server.service

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.