For whatever reason, we do no longer need to be root (or using sudo
) to run /sbin/shutdown
, /sbin/reboot
etc.
This seems to be because those executables are now symlinks to /bin/systemctl
which handles everything as normal user.
However, what if I want shutdown
and reboot
to require root authentication again? How can I achieve this?
Systemd does indeed handle the
shutdown
,reboot
and other commands, and the default privileges assigned are permissive. To change this, you need to create a Polkit rule. Create a.pkla
file in/etc/polkit-1/localauthority/50-local.d
(say,confirm-shutdown.pkla
) containing:The various shutdown, reboot, etc. commands are, in Polkit terms, actions in
org.freedesktop.login1
, for example,org.freedesktop.login1.power-off
,org.freedesktop.login1.reboot
, etc. The specific problem here is the default configuration, which is in/usr/share/polkit-1/actions/org.freedesktop.login1.policy
:Note that it allows the active user to power off, reboot, etc.
You can use
chmod
command.If you want to give access to only root, you can write:
If you want to give permisson to the root and the sudo group then you can write:
If you want to change the group of the file from sudo to an another (like a user or admins) you need to type in:
If you want to revert back, run:
Note: you may have to use
sudo
to these command, or have logged in the root accountAs changing permissions of a symlink on a Linux system doesn't change the permissions of the link but instead the file it points to (In Ubuntu at least). I would think the safest way to accomplish this would be to remove the link, and recreate it with the required umask to obtain the result you desire.
Another related post can be found here
You can make a script that checks if user is running it with root permissions or not.
Then it will run systemctl command or return error.
Source
Try to change its permissions in terminal. You could make it executable only by by a certain group, such as wheel or admin. Sadly (or perhaps fortunately), a file can only have one group ownership so chown simply wouldn't work by itself. Try "sudo chown root:wheel /sbin/shutdown" and then "sudo chmod g+x /sbin/shutdown". This will make the file executable only by root and admins(shudders) and sudoers will be required to enter their passwords.