This guide shows you how to configure your Ubuntu system so that pressing the physical power button on your computer triggers a clean shutdown instead of the default action (which is often to suspend or show a dialog). This is useful for desktop users who want a quick, safe way to power off without navigating menus, or for those who find the default behavior unexpected. You’ll need access to a terminal and sudo privileges, which are standard on most Ubuntu installations.
What You’ll Need
- A computer running Ubuntu (any recent version, including 22.04 LTS or 24.04 LTS)
- An active user account with sudo (administrative) privileges
- Access to a terminal (Ctrl+Alt+T)
- Optional: a text editor like nano or gedit (nano is preinstalled)
Step-by-Step
- Open a terminal. Press Ctrl+Alt+T on your keyboard. If that doesn’t work, search for “Terminal” in the Activities overview.
- Check the current power button behavior. Run the following command to see what happens when you press the power button now:
gsettings get org.gnome.settings-daemon.plugins.power power-button-action
This will output something like
'suspend'or'interactive'. The default is usually'suspend'on laptops and'interactive'(shows a dialog) on desktops. - Set the power button to shutdown. To make the power button immediately shut down the system, run:
gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'shutdown'
This command changes the setting for your current user. If you want to apply it system-wide for all users, you’ll need to edit a configuration file instead (see the alternative method below).
- Verify the change. Run the first command again to confirm the output is now
'shutdown'. - Test it (optional but recommended). Save any open work, then press the power button. The system should begin a clean shutdown immediately. If it doesn’t, see the Troubleshooting section.
Alternative: System-wide configuration (for all users)
If you want the setting to apply to every user on the machine (for example, on a family computer), you can edit the logind configuration file:
- Create a custom logind config file. Run:
sudo nano /etc/systemd/logind.conf
(You can use any text editor you prefer.)
- Find the line for
HandlePowerKey. It will likely be commented out (starting with#). Change it to:HandlePowerKey=poweroff
Make sure there is no
#at the beginning of the line. - Save and exit. In nano, press Ctrl+O to save, then Ctrl+X to exit.
- Restart the logind service. Run:
sudo systemctl restart systemd-logind
This will apply the change. Note that this will log out all users, so do it when you’re ready.
Common Mistakes
- Editing the wrong file: The
gsettingscommand affects only the current user. If you’re trying to change it for all users, you must use the logind method. Mixing them up can lead to confusion about why the setting doesn’t apply. - Typing the action incorrectly: The value must be exactly
'shutdown'(with quotes) for gsettings, andpowerofffor logind. Misspelling or using uppercase will cause the command to fail silently. - Forgetting to uncomment the line: In logind.conf, if you leave the
#at the beginning, the setting is ignored and the default (which is usuallypowerofffor the power key) remains. - Not restarting logind: After editing logind.conf, you must restart the service or reboot for the change to take effect. Simply saving the file does nothing.
Tips
- Use the interactive option if you want a choice: If you prefer to see a dialog asking whether to shut down, restart, or cancel, set the value to
'interactive'instead of'shutdown'. This is a good middle ground. - Keep the power button for suspend on laptops: On a laptop, you might want the power button to suspend (save battery) while you use the lid to shut down. You can set the power button to
'suspend'and the lid close action to'shutdown'via the same gsettings keys. - Test with a short press: The setting applies to a short press of the power button. A long press (usually 4-5 seconds) will force a hardware shutdown, which is not a clean shutdown and should be avoided unless the system is frozen.
- Use the command line for quick changes: If you’re comfortable with the terminal, the gsettings command is faster than navigating GUI settings. You can also create a keyboard shortcut to run it.
Troubleshooting
- Power button still doesn’t shut down: First, check that you’ve set the correct value. Run
gsettings get org.gnome.settings-daemon.plugins.power power-button-actionand ensure it returns'shutdown'. If you edited logind.conf, verify the line is not commented and the service was restarted. Also, some desktop environments (like KDE) use their own settings; this guide is for the default GNOME desktop on Ubuntu. - System suspends instead of shutting down: This usually means the gsettings value is still
'suspend'. Re-run the set command and check for typos. If you’re using a laptop, there might be a separate setting for when the lid is closed that overrides the power button. - Changes revert after reboot: The gsettings command should persist, but if you’re using a corporate-managed system, a policy might override it. For logind, ensure your custom file is named correctly (e.g.,
logind.confis the main file, but you can create a drop-in file in/etc/systemd/logind.conf.d/for clarity). - Power button does nothing at all: If pressing the power button has no effect, your system might have a hardware issue, or the acpid daemon might be interfering. Check if acpid is running with
systemctl status acpid. If it is, you can disable it (not recommended unless you know what you’re doing) or configure it to ignore the power button.
Frequently Asked Questions
Will this damage my computer?
No. A clean shutdown via the power button is exactly the same as using the shutdown option in the menu. It ensures all processes are terminated properly and filesystems are unmounted safely.
Can I set the power button to restart instead?
Yes. For gsettings, use 'restart' as the value. For logind, use HandlePowerKey=reboot.
What if I press the power button accidentally?
If you set it to 'shutdown', the system will start shutting down immediately. To avoid accidental shutdowns, consider using 'interactive' which shows a confirmation dialog.
Does this work on Ubuntu Server?
Ubuntu Server typically doesn’t have a graphical environment, so the gsettings command won’t work. However, the logind method works on any systemd-based system, including servers, and the default for the power key is usually already poweroff.
Why is the default behavior different on my laptop?
Laptops often default to suspend on the power button to save battery when the lid is closed. This is a deliberate design choice to prevent accidental shutdowns. You can change it as described.
I don’t have sudo access. Can I still change this?
No, changing system-wide settings requires sudo. However, you can change the setting for your own user with gsettings without sudo, if your user is allowed to use gsettings (which is usually the case).
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Choosing a Gaming PC or Console for Open World Games
- Error Code 0x4005: Fixes for Windows Update
- How to Search Safari Tabs on iPhone
- Fix Brightness Control Not Working on Windows 10
- Fix Remote Procedure Call Failed Error in Windows
- Samsung Galaxy S 8GB vs 16GB: Real Difference