https://wiki.archlinux.org/api.php?action=feedcontributions&user=Keyle&feedformat=atomArchWiki - User contributions [en]2024-03-28T14:48:54ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Allow_users_to_shutdown&diff=303201Allow users to shutdown2014-03-05T00:44:51Z<p>Keyle: a->e</p>
<hr />
<div>[[Category:Security]]<br />
[[es:Allow Users to Shutdown]]<br />
[[id:Allow Users to Shutdown]]<br />
[[it:Allow Users to Shutdown]]<br />
[[ru:Allow Users to Shutdown]]<br />
[[tr:Kullanıcının bilgisayarı kapatabilmesine izin verme]]<br />
[[uk:Allow Users to Shutdown]]<br />
[[zh-CN:Allow Users to Shutdown]]<br />
== Button and Lid events ==<br />
<br />
The suspend, poweroff and hibernate button presses and lid close events are handled by ''logind'' as described in [[Power management#ACPI events]] page.<br />
<br />
== Using systemd-logind ==<br />
<br />
If you're using [[systemd]] (which is default in Arch Linux) and [[pacman|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]].<br />
<br />
To check if your session is active<br />
$ loginctl show-session $XDG_SESSION_ID --property=Active<br />
<br />
The user can then use ''systemctl'' commands in the command line, or add them to menus:<br />
$ systemctl poweroff<br />
$ systemctl reboot<br />
<br />
Other commands can be used as well, including {{ic|systemctl suspend}} and {{ic|systemctl hibernate}}. See the ''System Commands'' section in {{ic|man systemctl}}<br />
<br />
== Using sudo ==<br />
<br />
[[pacman|Install]] {{Pkg|sudo}}, and give the user [[sudo|sudo privileges]]. The user will then be able to use ''sudo systemctl'' commands in the command line or in menus:<br />
<br />
$ sudo systemctl poweroff<br />
$ sudo systemctl reboot<br />
<br />
Other commands can be used as well, including {{ic|sudo systemctl suspend}} and {{ic|sudo systemctl hibernate}}. See the ''System Commands'' section in {{ic|man systemctl}}<br />
<br />
=== Users without sudo privileges ===<br />
<br />
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.<br />
<br />
''user'' ''hostname'' =NOPASSWD: /usr/bin/systemctl poweroff,/usr/bin/systemctl halt,/usr/bin/systemctl reboot<br />
<br />
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.<br />
<br />
== Creating aliases ==<br />
<br />
For convenience, you can add these [[Bash#Aliases|aliases]] to your user's {{ic|~/.bashrc}} if you have it enabled (or to {{ic|/etc/bash.bashrc}} for system-wide settings):<br />
<br />
alias reboot="sudo systemctl reboot"<br />
alias poweroff="sudo systemctl poweroff"<br />
alias halt="sudo systemctl halt"</div>Keyle