Allow users to shutdown: Difference between revisions

From ArchWiki
(fixed section fragments (interactive))
Tag: New redirect
 
Line 1: Line 1:
[[Category:System administration]]
#REDIRECT [[Power management#Allow users to shutdown]]
[[es:Allow users to shutdown]]
[[ja:ユーザーにシャットダウンを許可]]
[[ru:Allow users to shutdown]]
[[zh-hans:Allow users to shutdown]]
{{Merge|Power management|No need to split this off from the main article}}
 
== 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]] {{Pkg|polkit}}, users with non-remote session can issue power-related commands as long as [[General troubleshooting#Session permissions|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 {{ic|systemctl suspend}} and {{ic|systemctl hibernate}}. See the ''System Commands'' section in {{man|1|systemctl}}.
 
== Using sudo ==
 
[[Install]] {{Pkg|sudo}}, and give the user [[sudo|sudo privileges]]. The user will then be able to use the {{ic|sudo systemctl}} commands (e.g. {{ic|sudo systemctl poweroff}}, {{ic|sudo systemctl reboot}}, {{ic|sudo systemctl suspend}} and {{ic|sudo systemctl hibernate}}). See the ''System Commands'' section in {{man|1|systemctl}}
 
=== 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 {{ic|/etc/sudoers}} using the {{ic|visudo}} 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 {{ic|sudo systemctl poweroff}}, and reboot with {{ic|sudo systemctl reboot}}. Users wishing to power down a system can also use {{ic|sudo systemctl halt}}. Use the {{ic|NOPASSWD:}} tag only if you do not want to be prompted for your password.

Latest revision as of 15:29, 16 February 2023