How to Change the Lid Close Action in Ubuntu 22.04 / 20.04 Laptop

Running Ubuntu on Laptop? Here’s the beginner’s guide shows how to configure and tell what to do when the lid is closed.

By default Ubuntu will go suspend when you close the laptop lid. There’s no option to change this action since the relevant settings in Dconf Editor do not work.

What if you want your machine go to sleep, power off, hibernate, or just do nothing when you close the laptop lid? Well, you can do this by changing the configuration file for the systemd-logind service.

1. Edit the systemd-logind config file:

Firstly open terminal by either pressing Ctrl+Alt+T on keyboard, or searching from ‘Activities’ overview. When it opens, run command to edit the config file:

sudo -H gedit /etc/systemd/logind.conf
For Ubuntu 22.10, replace gedit with gnome-text-editor. Or, just use nano instead if you don't know your system default text editor.

About the key lines:

Remove ‘#‘ at the beginning to enable the line, and change the value!

  • HandleLidSwitchDocked=ignore – If your system is inserted in a docking station, or if more than one display is connected, then the action occurs if specified.
  • HandleLidSwitchExternalPower=suspend – If your system is on external power, the action occurs if specified.
  • HandleLidSwitch=suspend – For all other cases, the value of HandleLidSwitch will occur if enabled.

About the key values:

The value for the lid close behavior can be:

  • ignore – do nothing.
  • poweroff – shutdown machine.
  • reboot – restart the system.
  • lock – screen lock all running sessions.

You can also set the value to suspend, hibernate (make sure if hibernate works firstly), halt, hybrid-sleep (save system state to both disk & RAM), suspend-then-hibernate, or even kexec system call.

2. To make things simple:

To change lid close action without any condition, enable (remove ‘#’) the #HandleLidSwitch=suspend line and change the value to ‘ignore‘, ‘lock‘, ‘poweroff‘, etc.

To tell Ubuntu what to do when your notebook plugged, also remove # from #HandleLidSwitchExternalPower=suspend line and change its value.

For multi-display or dock station, remove # from #HandleLidSwitchDocked=ignore to enable it and set a value.

3. Apply changes:

After changes, save the file and restart the logind service by running command in terminal:

systemctl restart systemd-logind.service
SAVE YOUR WORK before running the command as it will log out the current session.

Merilyn Ne
Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.