shutdown vs shutdown now - shutting down system as non-root
Not actually my answer – just reposting an answer that, sadly, has been deleted for unknown reasons.
In Arch Linux, under certain circumstances, you may very well shutdown/reboot/hibernate... your pc without root privileges.
The Arch Linux Wiki page on Power Management under Systemd states:
polkit is necessary for power management as an unprivileged user. If you are in a local systemd-logind user session and no other session is active, the following commands will work without root privileges:
systemctl poweroff
systemctl reboot
systemctl suspend
systemctl hibernate
To check whether you are allowed to do this (i.e., you have polkit installed, and your session is not broken) you can use the following command:
$ loginctl show-session $XDG_SESSION_ID --property=Active
Active=yes
On other systemd
systems, like my Debian 8, this is not possible despite having the same reply to this command:
$ loginctl show-session $XDG_SESSION_ID --property=Active
Active=yes
$ systemctl reboot
==== AUTHENTICATING FOR org.freedesktop.login1.reboot ===
Authentication is required for rebooting the system.
Authenticating as: ,,, (myusername)
Password:
which indicates that polkit
has been set up by default in different ways on Arch Linux and Debian. The Arch Linux people see an advantage of this over sudo
, in that they state, in the wiki page on Polkit:
Polkit is used for controlling system-wide privileges. It provides an organized way for non-privileged processes to communicate with privileged ones. In contrast to systems such as sudo, it does not grant root permission to an entire process, but rather allows a finer level of control of centralized system policy.
As usual, YMMV.
As for shutdown now
, my guess is that it is a redirection to systemctl poweroff
, which is allowed to a non-privileged user.
-- https://superuser.com/users/255732/mariusmatutiae
Related videos on Youtube
Carsten Hagemann
Updated on September 18, 2022Comments
-
Carsten Hagemann over 1 year
I just observed something strange.
Logged into an archlinux system as a non-privileged user, I executed
shutdown
. As expected, it returnedMust be root.
To my surprise, executing
shutdown now
it (apparently!) does not check if the current user has root privileges. It simply shuts down the machine.I tried reproduced this both in a tty and a terminal in the Plasma DE.
I'm running Archlinux with an 4.2.2 Kernel with current packages.
I don't think this is related with GUI policies.
tl;dr: shutting down system as non-root with
shutdown now