How to shutdown and reboot without sudo password?
September 25th, 2007 mysurface Posted in Admin, chmod, shutdown, sudo | Hits: 210819 | 23 Comments »
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







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.
December 2nd, 2010 at 7:44 am
hal:
dbus-send –system –print-reply –dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
consolekit:
dbus-send –system –print-reply –dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
February 1st, 2011 at 9:58 pm
thanks a lot!
February 24th, 2011 at 10:42 pm
May 6th, 2014 at 6:11 pm
sudo shutdown -h now
this command needs password
March 11th, 2015 at 4:24 am
[…] Now you have to be able to execute the sudo shutdown -P 0 with no password. […]
March 29th, 2015 at 11:22 am
[…] Now you have to be able to execute the sudo shutdown -P 0 with no password. […]
May 9th, 2015 at 1:52 pm
Very great post. I simply stumbled upon your weblog and wished to mention that I have
really enjoyed surfing around your weblog posts. In any case I
will be subscribing for your feed and I am hoping you
write again very soon!
July 8th, 2015 at 2:32 pm
Wow! In the end I got a blog from where I be capable
of truly get useful information concerning my study and knowledge.
November 14th, 2015 at 12:09 am
[…] can use one of these methods to make it so sudo loadkeys doesn’t actually require your password from you (I suggest method […]
May 7th, 2016 at 10:13 am
Thanks for sharing this nice webpage
May 7th, 2016 at 10:13 am
You’ve superb information right here
August 16th, 2016 at 10:04 pm
Pretty insightful… looking frontward to coming back again
November 3rd, 2016 at 6:00 am
[…] followed this tut http://linux.byexamples.com/archives/315/how-to-shutdown-and-reboot-without-sudo-password/ and the second example is pretty much what I got above that didn’t work for […]