How to shutdown and reboot without sudo password?
September 25th, 2007 mysurface Posted in Admin, chmod, shutdown, sudo | Hits: 22878 |
If you are gnome user, you probably enjoy shutdown with just a click on the dialog. In order to shutdown from command line, you are requested to be either root or using sudo, such as
sudo shutdown -h now
For more detail examples of shutdown, continue to read here.
With sudo, you need to type your password. Sometimes it will be more convenient to us if we are able to shutdown without sudo. Is it possible?
The answer is yes, there are two ways to do that (Any other ways available?)
1. Adding suid mode to /sbin/shutdown
2. Modify /etc/sudoers with visudo
1. Adding suid mode to /sbin/shutdown
By adding suid mode to shutdown command, you are allowing regular user to run shutdown command as root.
sudo chmod u+s /sbin/shutdown
Check out examples of chmod here.
Now you can run shutdown without needing sudo.
2. Modify /etc/sudoers with visudo
This seems to be proper way to allow a command to run as root from specified users without needing to type password.
sudo visudo
By running visudo, it leads to edit /etc/sudoers.
Adding the line below to that file, assume mysurface is the user that allow to shutdown without password.
mysurface ALL = NOPASSWD: /sbin/shutdown
For ubuntu, usually the default user is in the %admin group. Therefore, you can also allow all users from the %admin group to shutdown without password.
%admin ALL = NOPASSWD: /sbin/shutdown
In fact, you still need sudo to shutdown, but this time you do not need to specified password.
sudo shutdown -h now
You can also reboot the system by using shutdown command too.
sudo shutdown -r now
Live Chat!









September 25th, 2007 at 5:45 am
some additional entry for people using Fedora based distro :)
On Fedora based system, /usr/bin/poweroff, /usr/bin/reboot, and /usr/bin/halt are managed through pam. Any local user can shutdown or reboot without root access.
So, if you are physically on a computer, you can shutdown/reboot as you wish without root access. But you’ll need root/sudo if you are going to shutdown/reboot through SSH.
October 3rd, 2007 at 12:25 am
how about sudo init 6 (reboot) or sudo init 0 (shutdown) ??
October 3rd, 2007 at 12:40 am
Its either you chmod /sbin/init with suid, or insert it to /etc/sudoers just like the example shows at above.
November 19th, 2007 at 10:33 am
If you are using KDE this method used by the Amarok plugin nightIMPgale might work for you:
dcop --all-sessions --all-users ksmserver ksmserver logout 0 2 0 && exit 0