Ubuntu – How to set that only root + a given user can shut down the pc

linuxSecurityshutdownUbuntu

If I'm using Ubuntu 11.04, how can I configure it such that that only two users can shut down/suspend/hibernate my PC: the root user and one regular user?

Best Answer

The shutdown binary will only work for the root user. The typical approach to this is to set up sudo rules to allow the user to execute shutdown as root. Assuming the user doesn't already have full sudo permissions (the first user on an Ubuntu desktop system does, for example) you might add the following line to /etc/sudoers (using the visudo utility, for safety):

joe    hostname=(root) /sbin/shutdown -h now

If you want them to be able to shut down without being prompted for their password, then add the NOPASSWD option, like this:

joe    hostname=(root) NOPASSWD: /sbin/shutdown -h now

You can modify the way they can run shutdown by using wildcards or explicit declarations. For example shutdown -h now allows an immediate halt of the system, it will not reboot. You could allow -r instead to reboot the system.

After you configure sudoers, joe can run the following command to reboot the system:

sudo /sbin/shutdown -h now

As joe, you can run the following command to see what commands you have access to run using sudo:

sudo -l