How to shutdown and reboot without sudo password?
September 25th, 2007 mysurface Posted in Admin, chmod, shutdown, sudo | Hits: 50264 |
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 0October 29th, 2008 at 6:12 am
you can also use nano or mousepad such as
sudo mousepad /etc/sudoers
sudo nano /etc/sudoers
June 6th, 2009 at 3:34 pm
calito Says:
you can also use nano or mousepad such as
sudo mousepad /etc/sudoers
sudo nano /etc/sudoers
This is dangerous, you should always use visudo to edit sudoers, it checks if there are any syntax errors, and warns user. If you want to use e.g. mousepad, export it to EDTOR -enviromental variable (\’export EDITOR=\\"mousepad\\"\’ in bash, \’setenv EDITOR mousepad\’ in tcsh), then just type sudo visudo.
December 3rd, 2009 at 11:48 pm
how do i undo this…
i think i did something wrong and now i cant use sudo…
December 4th, 2009 at 8:54 am
@kira
Get the live cd of your linux distribution and copy out /etc/sudoers to replace your existing one.
January 15th, 2010 at 2:47 am
This was helpful. Thanks!
February 7th, 2010 at 4:17 pm
There is no sudo in Mandriva2010. You must install it using urpmi sudo.