103

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.

Alvar
  • 17,058
NaN
  • 1,415

9 Answers9

94

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.

Zanna
  • 70,465
Bruno Pereira
  • 73,643
46

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.

muru
  • 197,895
  • 55
  • 485
  • 740
  • 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 at M.academy 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
  • Note: there were other answers, that have been helpful. The most important thing though is to restart the acpi daemon (acpid). Furthermore sometimes you need to press the button (e.g. on my Zenbook UX32VDA) just a tiny bit longer in order for it to get caught by the system. – Igor Jan 05 '18 at 03:27
  • And this is what Linux is all about! Bypassing all the GUI mambo jumbo and making changes directly! – Antony Feb 15 '19 at 18:28
32

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
Phil Hord
  • 128
  • Thanks exactly what I was looking for on Ubuntu 11.10: gsettings set org.gnome.settings-daemon.plugins.power button-power 'suspend' – c0de Dec 03 '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 09: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 09: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! – Phil Hord Feb 14 '17 at 20:31
13

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.

gojomo
  • 181
9

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 02: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 08:42
8

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

rulet
  • 331
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 08 '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 08 '18 at 13:35
1

For current Ubuntu and Lubuntu systems:

echo "HandlePowerKey=suspend" | sudo tee -a /etc/systemd/logind.conf
sudo service systemd-logind suspend
cmcginty
  • 5,888
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