Difference between revisions of "Allow users to shutdown"

From ArchWiki
Jump to: navigation, search
(Root not needed for power commands with an active session.)
('poweroff' is aliased to systemctl, so 'poweroff' alone is enough; added a command to check if your session is active)
Line 10: Line 10:
  
 
If you're using [[systemd]] (which is default in Arch Linux), users with non-remote session can issue power-related commands as long as {{pkg|polkit}} is installed and [[xinitrc#Preserving the session|the session is not broken]].
 
If you're using [[systemd]] (which is default in Arch Linux), users with non-remote session can issue power-related commands as long as {{pkg|polkit}} is installed and [[xinitrc#Preserving the session|the session is not broken]].
 +
 +
To check if your session is active
 +
$ loginctl show-session $XDG_SESSION_ID --property=Active
  
 
To shutdown:
 
To shutdown:
  $ systemctl poweroff
+
  $ poweroff
  
 
The suspend, poweroff and hibernate button presses and lid close events are also handled by ''logind'' as described in [[Power Management#ACPI events]].
 
The suspend, poweroff and hibernate button presses and lid close events are also handled by ''logind'' as described in [[Power Management#ACPI events]].

Revision as of 16:26, 16 September 2013

Using systemd-logind

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

To check if your session is active

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

To shutdown:

$ poweroff

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

Using sudo

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: This method relies on /usr/bin/shutdown, which is only provided by systemd-sysvcompat and in fact links to /usr/bin/systemctl. (Discuss in Talk:Allow users to shutdown#)

First install sudo:

# pacman -S sudo

Then, as root, add the following to the end of /etc/sudoers using the visudo command. Substitute user for your username and hostname for the machine's hostname.

user hostname =NOPASSWD: /usr/bin/shutdown -h now,/usr/bin/halt,/usr/bin/poweroff,/usr/bin/reboot

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

For convenience, you can add these aliases to your user's ~/.bashrc if you have it enabled (or to /etc/bash.bashrc for system-wide settings):

alias reboot="sudo reboot"
alias poweroff="sudo poweroff"
alias halt="sudo halt"

Using acpid

acpid can be used to allow anyone with physical access to cleanly shut down the computer by using this power button.