This is something that was bothering me for quite a while. Rarely but I happened to press accidentally the power button and shut down my computer, loosing all unsaved work. These few times I tried to search for solution, it never worked. After another undesired power off I decided to sit down and fix it.

Why I never managed to get it working properly is due to the combination of systemd and Openbox. Both are capable to set what the special buttons like power or sleep do. So fixing it in the either one kept the button misbehaving. And the trick was to configure it in both places.

Let's first disable the button in Openbox. Edit ~/.config/openbox/rc.xml and find the XF86PowerOff piece and comment it out by wrapping it between <!-- and -->:

<keybind key="XF86PowerOff">
  <action name="Execute">
    <command>systemctl poweroff</command>

Reload the Openbox config file:

$ openbox --reconfigure

Time for the systemd part. Open /etc/systemd/logind.conf and find the line with HandlePowerKey in it. By default the value for the power button handler is poweroff. Remove the preceding # symbol and change the value to ignore:


Lastly, restart logind:

$ sudo systemctl restart systemd-logind

And we're done. Now the power button is harmless. Of course it will continue working to power on the computer or wake it up from the sleep.

P.S. In case something doesn't work, check the logs ( -f for real time update):

$ sudo journalctl -f