How do I disable the Power button?

Has anyone managed to disable the Power button? I have a desktop where it is easy to hit it on the keyboard by mistake, and it isn’t really needed, so I tried to disable it. I created a /etc/systemd/logind.conf.d/uddeborg.conf file with these contents:

[Login]
HandlePowerKey=ignore

But pressing the button still triggers this message in the journal

sep 12 10:28:59 freddi systemd-logind[661]: Power key pressed short.
sep 12 10:29:00 freddi systemd-logind[661]: The system will power off now!
sep 12 10:29:00 freddi systemd-logind[661]: System is powering down.

I also tried to put the disabling directly in /etc/systemd/logind.conf but that didn’t make any difference.

What am I missing?

According to https://www.baeldung.com/linux/power-button-behavior you are doing the right things.

Did you restart the service for the changes to take effect?

sudo systemctl restart systemd-logind
2 Likes

Yes, I’ve restarted the service, and also tried again after the machine was rebooted (since it went down when I tried if it worked).

Has anyone else got it working?

gsettings set org.gnome.settings-daemon.plugins.power \
    power-button-action "nothing"

sudo -u gdm dbus-launch \
gsettings set org.gnome.settings-daemon.plugins.power \
    power-button-action "nothing"
2 Likes

So there are settings on the desktop level! I wasn’t looking there. (After all, the log entries pointed to systemd-logind.)

Now, I do run sddm and KDE/Plasma, so these particular settings probably don’t apply, but I’ll look for something similar in my environment.