Change the power button behavior

To customize the action of the power button, you can change its default behavior both when GNOME is running and when it is not running.

Change the behavior of the power button when GNOME is not running

To prevent the system from shutting down when you press the power button, modify settings for the non-graphical systemd target. Select the option according to requirement.

Before you begin

  • You have administrative privileges.

Procedure

  1. Edit the /etc/systemd/logind.conf configuration file to set the HandlePowerKey variable.
  2. To reboot the system when you press the power button, set the reboot value:
    HandlePowerKey=reboot

    Use one of the following options:

    • poweroff: Shut down the computer.
    • reboot: Reboot the system.
    • halt: Initiate a system halt.
    • kexec: Initiate a kexec reboot.
    • suspend: Suspend the system.
    • hibernate: Initiate system hibernation.
    • ignore: Do nothing.
  3. Restart the systemd-logind service to apply the changes:
    # systemctl reload systemd-logind

Change the behavior of the power button in GNOME

To prevent the system from suspending when you press the power button, modify settings for the GNOME login screen and user session. You can select one of the options: physically on a system or virtually from a remote console.

Before you begin

  • You have administrative privileges.

Procedure

  1. Create a local database for system-wide settings in the /etc/dconf/db/local.d/01-power file:
    [org/gnome/settings-daemon/plugins/power]
    power-button-action=<value>

    Replace <value> with one of the following power button actions:

    • nothing: Does nothing.
    • suspend: Suspends the system.
    • hibernate: Hibernates the system.
    • interactive: Shows a pop-up query asking the user what to do.

      In the interactive mode, when you press the power button, the system automatically powers off after 60 seconds. You can select a different behavior from the pop-up query.

  2. Optional: To override existing settings and prevent other users from changing it, edit configuration in the /etc/dconf/db/local.d/locks/01-power file:
    /org/gnome/settings-daemon/plugins/power/power-button-action
  3. Update the system databases:
    # dconf update
  4. Log out and log in again for the system-wide settings to take effect.

Results

  • Press the power button and check if the system performs the action you configured.