I would like my computer to shut down when I press the power button. Without any questioning.

First problem is, that a dialog pops up which I have to click. How to remove this?

Second problem is, that when the current user is not sudoer and anoter user is logged in on a console, my computer does not shut down. Instead the desktop user is just logged out.

Perhaps it is possible to bind the command shutdown -h now to the power button event shomehow?

  • 2
    What version of Ubuntu? This might not be a duplicate if this is for Ubuntu 13.04, or 13.04 with a different Desktop environment, etc..
    – belacqua
    Jun 13, 2013 at 20:00

1 Answer 1


Ubuntu has a menu entry which allows you to bind keyboard events to commands. I would assume that the action triggered by the power button would also be accessible from this menu. Make a script called 'shutdown.sh' (or something) and put it in your home directory. It's contents should simply be 'shutdown -h now'. Run 'sudo chmod +x shutdown.sh' to make it executable. In a terminal, run 'sudo nano /etc/sudoers', this is will open a text file for editing. Open it with a GUI text editor by replacing 'nano' with 'leafpad', 'gedit', etc. - whatever you have installed.

Add these lines to the end of the text file:

Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/halt, /sbin/reboot

Obviously, replace '' with your actual username. Save the changes you made (using Ctrl+o if you're using nano) Finally, configure the power button to launch your script using the Ubuntu keyboard menu. Like I said, I don;t use Unity so I am not sure of the exact procedure necessary to configure the power button to launch script, nor am I aware of the name of the key you will have to enter into the keyboard menu.

More information about editing the sudoers file can be found here: Ubuntu Sudoers

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