The physical power button on modern desktop computer towers and laptops is often positioned along the top edge, front chassis panel, or directly integrated into the keyboard cluster. In busy workspaces, brushing past your computer tower, picking up a laptop, or reaching for the Delete key often results in an accidental press of the power button. On default Ubuntu installations, an accidental tap can immediately trigger system shutdown or force sudden sleep mode, terminating unsaved documents and active terminal scripts.
Ubuntu allows you to customize the behavior of the physical hardware power button. You can configure it to display an interactive confirmation prompt, switch the action to sleep/suspend, or instruct the operating system to completely ignore power button presses while logged in. This tutorial explains how to adjust the power button action via the graphical control centre and systemd system configuration.
Configuring the Power Button in Ubuntu Graphical Settings
On modern versions of Ubuntu (including 22.04 LTS and 24.04 LTS), configuring the action takes less than a minute:
- Click the System Menu in the top-right corner of your desktop panel (the volume/battery cluster) and open Settings.
- In the left-hand navigation sidebar, click on Power.
- Scroll down to the General section.
- Locate the setting labelled When the Power Button is Pressed (or Power Button Behavior).
- Click the dropdown menu and select your preferred operational response:
- Suspend: Puts the PC into low-power sleep mode without closing applications.
- Power Off: Prompts the standard 60-second shutdown countdown dialogue so you can cancel accidental presses.
- Nothing: Completely ignores physical button presses during desktop operation.
- Close Settings to apply the change immediately.
Configuring Power Button Behavior via systemd (logind.conf)
If you are managing desktop servers or want to ensure the power button behavior is enforced globally at the low-level system daemon level:
- Open the Terminal by pressing Ctrl + Alt + T.
- Open the
logind.confconfiguration file with root privileges:sudo nano /etc/systemd/logind.conf - Look for the line containing
#HandlePowerKey=poweroff. - Remove the leading
#symbol to uncomment the directive and modify its value:- To ignore the button completely:
HandlePowerKey=ignore - To put the machine to sleep:
HandlePowerKey=suspend
- To ignore the button completely:
- Press Ctrl + O then Enter to save, followed by Ctrl + X to exit the nano editor.
- Restart the logind service to apply the new hardware policy:
sudo systemctl restart systemd-logind
Accidental physical bumps will no longer terminate your desktop sessions or drop remote SSH connections.