Allow users to shutdown

Button and Lid events

The suspend, poweroff and hibernate button presses and lid close events are handled by logind as described in Power management#ACPI events page.

Using systemd-logind

If you are using systemd (which is default in Arch Linux) and install polkit, users with non-remote session can issue power-related commands as long as the session is not broken.

To check if your session is active

$ loginctl show-session $XDG_SESSION_ID --property=Active

The user can then use systemctl commands in the command line, or add them to menus:

$ systemctl poweroff
$ systemctl reboot

Other commands can be used as well, including systemctl suspend and systemctl hibernate. See the System Commands section in systemctl(1).

Using sudo

Install sudo, and give the user sudo privileges. The user will then be able to use the sudo systemctl commands (e.g. sudo systemctl poweroff, sudo systemctl reboot, sudo systemctl suspend and sudo systemctl hibernate). See the System Commands section in systemctl(1)

Users without sudo privileges

If users should only be allowed to use shutdown commands, but not have other sudo privileges, then, as root, add the following to the end of using the command. Substitute user for your username and hostname for the machine's hostname.

user hostname =NOPASSWD: /usr/bin/systemctl poweroff,/usr/bin/systemctl halt,/usr/bin/systemctl reboot

Now your user can shutdown with sudo systemctl poweroff, and reboot with sudo systemctl reboot. Users wishing to power down a system can also use . Use the tag only if you do not want to be prompted for your password.

gollark: I mostly use postgres.
gollark: Ah, so this is why universities are so expensive now.
gollark: <@350812024055398401> Good question. I can't really test that very easily, since that's only done on the actual school-owned computers (personal devices you bring in and connect to their wifi network seem to have less restricted outbound access, though I'm sure they're logging as much as possible).
gollark: My school *does* MITM every connection made on the inschool computers! Yay!
gollark: Try Docker Compose next, it's very cool.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.