What is the proper way to enable a normal user to shutdown, halt or reboot the computer?
Solution 1
All users? Or a selected subset of them? Will they use the computer locally or also remotely (e.g. via ssh).
In case of a few users who also work remotely sudo will work fine. See this link for details.
If they are logging in locally and via a GUI then there are better options. E.g. capturing the three finger salute via init and letting that trigger a 1 minute delayed shutdown. It has been ages since I set that up though, so I skipping on the details for that. (I used that back when Slackware 3 was modern)
Solution 2
If your shutdown
accepts the -a
switch (check with shutdown --help
), you can do the following:
-
Add the users that should be able to shut the system down to
/etc/shutdown.allow
.Example:
userA userB
-
Shut the system down using the
-a
switch.Example:
shutdown -a -h now
Source: UNIX man pages : shutdown (8)
Solution 3
I use SL 6.4. It has user version of poweroff, halt, reboot provided by usermode package. I can shutdown, reboot as a normal user (from the command line as well)
$ which {poweroff,reboot,halt}
/usr/bin/poweroff
/usr/bin/reboot
/usr/bin/halt
rpm -qf $(which poweroff reboot halt)
usermode-1.102-3.el6.x86_64
usermode-1.102-3.el6.x86_64
usermode-1.102-3.el6.x86_64
As root
# which {poweroff,reboot,halt}
/sbin/poweroff
/sbin/reboot
/sbin/halt
# rpm -qf $(which poweroff reboot halt)
upstart-0.6.5-12.el6.x86_64
upstart-0.6.5-12.el6.x86_64
upstart-0.6.5-12.el6.x86_64
Related videos on Youtube
Comments
-
ccpizza almost 2 years
My dirty solution is to
chmod +s /sbin/shutdown
. It works but this is probably not good practice and insecure. Moreover after some system updates the suid bit gets reset. What would be the correct way to do it?-
kobaltz almost 12 yearsi usually do
sudo shutdown now -h
-
-
ccpizza almost 12 yearsEither a single user or a group such as %users. The idea is to avoid using
sudo
every time and entering passwords. According to the link you posted a line in sudoers like%users ALL=NOPASSWD:/sbin/shutdown
is probably all I need. Thank you! -
ccpizza almost 12 yearslooks like my version of
shutdown
(generic Linux of the -buntu family) does not support the-a
option. Looks like the expected way is to create a %shutdown group which would include the users who need to shutdown and then reference that in the sudoers file.