93

When I press the power button a dialog opens, but I want to shutdown the system without receiving "Do you really really want to shutdown?". How can I choose a direct shutdown action on a pressed power button?

I had the same problem with the 11.04 version, but I don't remember the solution and yesterday I upgraded to Ubuntu 11.10.

83

Lid Close Action

To set up the Laptop Lid Close Action you have to install Advanced Setting (or the Gnome Tweak Tool). It is in the USC (Ubuntu Software Center) under either tweak or Advanced Settings. If installed press the super button and type in tweak or advanced and choose the Advanced Settings. When it opens choose the shell tab;

Advanced Settings Before

Press the arrows and choose you desired on both on AC and on battery;

Advanced Setting After

Default buttons behavior

Install dconf-tools:

sudo apt-get install dconf-tools

Press alt+f2 and open dconf-editor (or in a terminal type dconf-editor)

Navigate to org.gnome.settings-daemon.plugins.power and set your default button-power action there:

enter image description here

On some systems you will also need to mark the item suppress-logout-restart-shutdown.

  • 1
    This would be a solution... for Ubuntu 11.04. He's talking about Ubuntu 11.10. – RobinJ Oct 15 '11 at 10:05
  • 1
    the answer is "fixed", its not a bug, its a "feature". – Bruno Pereira Oct 15 '11 at 10:45
  • 4
    I am really wondering if this means userfriendly if you need to install some app and change reg-files to make something trivial like that working. – n3rd Nov 1 '11 at 18:57
  • 2
    You can also use command lines for that, gsettings will do the job just fine. Its something that will be fixed soon I hope. Def not user friendly ;) – Bruno Pereira Nov 1 '11 at 19:05
  • 1
    The GNOME team has now decided that the shutdown option is "too destructive". Beware of upgrading to later versions of GNOME. – palswim Mar 17 '16 at 6:23
40

I'm afraid that the first answers didn't work for me, I think that the 'graphical solutions' only work for the upper right indicator, not for the power button. rulet solution works for me, I think I can improve it and make the prompt completely disappear. Instead of creating a new file you can use existing /etc/acpi/events/powerbtn file

sudo -H gedit /etc/acpi/events/powerbtn

Add # to comment line:

#action=/etc/acpi/powerbtn.sh

Add a new line:

action=/sbin/poweroff

Save file. Open a console and type:

sudo acpid restart

That works for me AND the prompt has gone, just like in ubuntu 11.04. Wish this helps.

  • Thanks I've been looking all over the place for an answer to this. All the other stuff about gsettings doesn't work for me on 12.04 with gnome shell. – frankster Oct 23 '12 at 18:53
  • Yes! This is also the only thing that worked for me in Ubuntu 12.04. Thank you very much. – Mark Shust Mar 31 '13 at 13:41
  • Yes, this works on Ubuntu 13.04. Other answers involving gsettings do not work (I guess, any more). – farfareast Jun 16 '13 at 19:56
  • 1
    This worked for me on Ubuntu 12.04 but to disable the prompt I had to set button-power option in org.gnome.settings-daemon.plugins.power in dconf-editor to nothing. – Abhinav Sarkar Jul 31 '13 at 16:26
  • Worked for me on Xubuntu 16.04. Did not want to install any additional apps as first solution mentioned. – DjBacon Jul 11 '16 at 13:27
30

This is the quick, simple answer I needed:

gsettings set org.gnome.settings-daemon.plugins.power button-power 'hibernate'

If you want to see your settings first, try this:

gsettings get org.gnome.settings-daemon.plugins.power button-power

Or maybe this if you want to see all the power settings:

gsettings list-recursively org.gnome.settings-daemon.plugins.power
  • Thanks exactly what I was looking for on Ubuntu 11.10: gsettings set org.gnome.settings-daemon.plugins.power button-power 'suspend' – c0de Dec 3 '11 at 11:05
  • 3
    To revert this change use: gsettings set org.gnome.settings-daemon.plugins.power button-power 'interactive' – c0de Jul 29 '13 at 9:39
  • Shouldn't it be gsettings set org.gnome.settings-daemon.plugins.power button-power 'shutdown' for non-interactive shutdown? It doesn't work for me, on 16.04, while the graphical solution with installing dconf-editor does. – Nickolai Leschov Apr 22 '16 at 19:25
  • to check that specific trigger press >$gsettings get org.gnome.settings-daemon.plugins.power – Pavlos Theodorou Feb 11 '17 at 9:34
  • @Pav I think the 'get' option didn't work for me correctly in 2011. It works in 16.10, so I added it to the answer. Thanks! – phord Feb 14 '17 at 20:31
11

I wanted to change the power button to suspend-to-RAM. On a Ubuntu 14.04 server (no Gnome/X), changing /etc/acpi/events/powerbtn to use an alternate action (/usr/sbin/pm-suspend) did not work.

Instead, adding a single line to /etc/systemd/logind.conf was enough to do the trick:

#HandlePowerKey=poweroff
HandlePowerKey=suspend

Now, pressing the power button causes instant suspend.

  • 1
    This is the only thing that worked for me (Ubuntu 14.04, Xmonad) – Andrew MacFie Jul 28 '15 at 22:24
  • Odd, this did not work for me on Ubuntu 14.04 LTS just now. dconf-editor solution worked for me. – Timothy C. Quinn Feb 15 '16 at 2:56
  • 1
    Worked for me on 16.04.1 – mcchots Jan 5 '17 at 17:12
  • This was also the only thing that worked for me with Ubuntu 16.04 and awesome window manager. – Robert Fleming Aug 10 '17 at 2:27
  • Did not work from me, with Ubuntu 16.04.3 (neither from fluxbox nor from tty1) – josinalvo Dec 13 '17 at 17:52
8

Bruno's answer is only half-correct.

After installing dconf, you should navigate to apps>indicator-session

Place a check mark for the item "suppress-logout-restart-shutdown."

This will work for Unity in Ubuntu 11.10 but not for Gnome 3 or Gnome Classic.

  • 1
    Your answer or the other answer will work in 11.10 but not Gnome3 or Classic? – belacqua Oct 22 '11 at 2:15
  • Interestingly, I observe that this only affects the dialog popup when using the indicator in the uppper right. Pressing the power button still shows the dialog. – Christoph Nov 21 '11 at 8:42
7

That didn't work for me in unity or gnome-shell(prompt was always shown). So I've used this manual

from arch linux wiki. I've created file /etc/acpi/events/power with the content:

event=button/power (PWR.||PBTN)
action=/sbin/poweroff

and executed a command:

sudo acpid restart (don't know exactly if it's right command)

And then by pressing hardware power-button computer shotdowns(the prompt will be shown, but that won't stop shutdown process).

  • 1
    That is more helpful for headless command-line-only systems. – BBK Aug 28 '12 at 16:02
  • 1
    That is helpful for any type of systems. – rulet Jan 13 '13 at 2:14
1

For me the solution was was this:

gsettings set org.gnome.settings-daemon.plugins.power power-button-action suspend
  • 1
    Probably OK for standard Ubuntu using Gnome Shell, but the question was asked nine years ago and thus related to the Unity desktop.This may have changed in the mean time. – vanadium Sep 8 '18 at 13:31
  • 1
    @vanadium gsettings attributes have been almost the same I think. Regardless of that, this question shows up in Google Search as the first one so this answer might be useful for someone. – Oliver Tušla Sep 8 '18 at 13:35
0

None of this worked on my 13.04 system. In the end I re-compiled gnome-session.

In gsm_shell.c and gsm_logout_dialog.c change #define AUTOMATIC_ACTION_TIMEOUT from 60 to 5

0

For current Ubuntu and Lubuntu systems:

echo "HandlePowerKey=suspend" | sudo tee -a /etc/systemd/logind.conf
sudo service systemd-logind suspend

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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