Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking to migrate a Snoozer application I originally wrote in windows on AutoIt, which when it comes down to it is a Shutdown Snoozer.

I list faling asleep to a movie or show, but I wake up if my pc runs through the night. So I built an application which notifies you that there is a pending shutdown and you have 10 minutes to snooze this otherwise the PC shuts down. The application allows you to repeat this prompt for X times and on a Y interval.

My question is, in Ubuntu will I need sudo rights to shutdown. If so, how can I prevent the application from continually asking the user to authenticate as sudo in order to shutdown the system properly??

share|improve this question
up vote 0 down vote accepted

Yes, the user need to have sudo rights, but you can use NOPASSWD to skip password authentication anyway.

To allow a user to run specific commands, in this case, the shutdown command, edit the /etc/sudoers file, for example:

user ALL=/usr/bin/apt-get,/sbin/shutdown

A more detailed version which suits your requirement better (user can shut down using sudo shutdown -h now and reboot with sudo reboot. Users wishing to power down a system can also use poweroff or halt without password):

user hostname =NOPASSWD: /sbin/shutdown -h now,/sbin/halt,/sbin/poweroff,/sbin/reboot

You can use the following command to show what the user can run will tell us what commands the user can run with sudo:

sudo -U user –l
share|improve this answer
Thank you so much, this is definately helpfull! – Rudi Strydom Nov 8 '12 at 16:14

A very long time ago, I wrote this for someone with the same question. I have no idea if it still works and can't test right now because I don't want to restart :-).

Here you go:

#!/usr/bin/env python

import dbus

def main():
    answer = raw_input("Do you really want to shutdown your computer? (Y/n): ")
    if answer in ('y', 'Y', ''):
        bus = dbus.SystemBus()
        bus_object = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer")

if __name__ == "__main__":
share|improve this answer
Thank you Timo, I am still writing the UI and saving the application states. I will definately test it once I am ready. – Rudi Strydom Nov 8 '12 at 16:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.