How to shutdown and reboot without sudo password?

September 25th, 2007 mysurface Posted in Admin, chmod, shutdown, sudo | Hits: 236959 | 25 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

25 Responses to “How to shutdown and reboot without sudo password?”

  1. 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.

  2. how about sudo init 6 (reboot) or sudo init 0 (shutdown) ??

  3. Its either you chmod /sbin/init with suid, or insert it to /etc/sudoers just like the example shows at above.

  4. 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

  5. you can also use nano or mousepad such as
    sudo mousepad /etc/sudoers
    sudo nano /etc/sudoers

  6. CryptoKid Says:

    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.

  7. how do i undo this…

    i think i did something wrong and now i cant use sudo…

  8. @kira
    Get the live cd of your linux distribution and copy out /etc/sudoers to replace your existing one.

  9. This was helpful. Thanks!

  10. There is no sudo in Mandriva2010. You must install it using urpmi sudo.

  11. hal:
    dbus-send –system –print-reply –dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown

    dbus-send –system –print-reply –dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

  12. thanks a lot!

  13. debabrata Says:

    sudo shutdown -h now
    this command needs password

  14. […] Now you have to be able to execute the sudo shutdown -P 0 with no password. […]

  15. […] Now you have to be able to execute the sudo shutdown -P 0 with no password. […]

  16. 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!

  17. Wow! In the end I got a blog from where I be capable
    of truly get useful information concerning my study and knowledge.

  18. […] can use one of these methods to make it so sudo loadkeys doesn’t actually require your password from you (I suggest method […]

  19. Thanks for sharing this nice webpage

  20. You’ve superb information right here

  21. Pretty insightful… looking frontward to coming back again

  22. […] followed this tut and the second example is pretty much what I got above that didn’t work for […]

Leave a Reply