Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Mitch, user68186, aquaherd, Eric Carvalho, poolie Jun 14 '13 at 3:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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 '13 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 '' (or something) and put it in your home directory. It's contents should simply be 'shutdown -h now'. Run 'sudo chmod +x' 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

share|improve this answer

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