How do I prevent access to shutdown but not reboot?
I have a ubuntu pc running as a plex server. How do I get it so that no one can shutdown the computer but only allow the user to reboot the machine? I know it is possible in windows but I am just wondering if it is possible on ubuntu.
The most effective way to do this would be to mask the power off target like this:
sudo systemctl mask poweroff.target
Now it will be impossible for anyone to shut down the machine unless they hold down the power button or physically disconnect the machine from power.
Rebooting is unaffected by this mask.
In the event you need to shut the machine down in the future for maintenance or hardware replacement, you can unmask
the target:
sudo systemctl unmask poweroff.target
If you just need to give the power to reboot to non-admin users, you can add an entry for them in your sudoers
file for reboot
(and/or systemctl reboot
, depending what you want them to run). Then they will be able to run sudo reboot
(and/or sudo systemctl reboot
). This answer assumes that they do not otherwise have access to sudo
— i.e., that they are normal, non-admin users that are not part of the wheel
group.
The sudoers
file lives at /etc/sudoers
, but you should not edit it directly. Rather, you should only edit it using visudo
. You'll need to be root to edit it, so you'll run sudo visudo
. The visudo
command will verify the syntax of your edits, and you should always use this to avoid breaking your config and preventing yourself gaining root access in the future.
Then you can add the something like following lines to your sudoers
file:
username ALL=(root): /usr/sbin/reboot
username ALL=(root): /usr/bin/systemctl reboot
where username
is the user's username (or %groupname
for a group), and where the paths are the actual paths to the commands on your system (check with which
, e.g., which reboot
.).
For more information, check out man sudoers
, man sudo
, and man visudo
.