Change Lid Close Behavior in Ubuntu 24.04 | 22.04 | 20.04

Last updated: January 18, 2025

This simple tutorial shows how to change the action (e.g., power off, hibernate, do nothing, or lock) when laptop lid is closed in Ubuntu 20.04, Ubuntu 22.04, and Ubuntu 24.04, while it suspends Ubuntu by default.

NOTE: This tutorial is also tested and works in Ubuntu 22.04, and Ubuntu 24.04 with default GNOME desktop environment. It should also works in other Linux uses systemd.

Dconf editor offers options to change the action to take when the laptop lid is closed on AC or power, but it doesn’t work!

Option 1: Edit logind.conf file

So far as I know, you can edit the logind.conf file to change the lid close action. And it should work on all Ubuntu desktop, server, and flavors.

1.) First, press Ctrl+Alt+T on keyboard to open up a terminal window. When it opens, run command to edit the config file:

sudo gedit /etc/systemd/logind.conf

Depends on your Ubuntu edition and desktop environment, replace gedit in command with gnome-text-editor for Ubuntu 24.04 and higher. Or, use mousepad for XFCE, pluma for MATE, or nano command line text editor that works in most desktops.

2.) When the file opens, find out the line #HandleLidSwitch=suspend and change it to one of following :

  • HandleLidSwitch=lock – lock when lid closed.
  • HandleLidSwitch=ignore – do nothing, some laptops will disconnect Wi-Fi.
  • HandleLidSwitch=poweroff – shutdown.
  • HandleLidSwitch=hibernate – hibernate Ubuntu.

NOTE: hibernation feature does NOT work out-of-the-box in Ubuntu, you have to enabled it first if need.

3.) Set lid close action when running on power supply or in docking station.

For choice, you may also uncomment ‘HandleLidSwitchExternalPower‘ and/or HandleLidSwitchDocked lines by removing # at their beginning, and change the value to lock, ignore, poweroff, or hibernate.

So the changes will also apply when your laptop is running with power supply, in a docking station, or with external displays.

4.) After saved the file (for nano, press Ctrl+S then Ctrl+X). Finally apply changes by running command to restart systemd-logind service:

systemctl restart systemd-logind.service

In current Ubuntu releases, the last command will log user out. But for Ubuntu 22.04 and higher, it’s better to restart computer instead.

Note: You have to do previous steps every time you want to change the action. And ‘Suspend when laptop lid is closed‘ option in Gnome Tweaks will no longer work before you comment (add # at the beginning) the line in /etc/systemd/logind.conf.

Option 2: Use A Drop-in under /etc/systemd/logind.conf.d

The first option works good in my case, but it’s recommended to create “drop-ins” in the /etc/systemd/logind.conf.d/ directory. So defaults can be easily restored by deleting main file and all drop-ins.

1. First, press Ctrl+Alt+T to open terminal. Then, run command create the directory in case it does not exit:

sudo mkdir -p /etc/systemd/logind.conf.d

2. Next, run command to create a ‘drop-in'(custom config file), for example lid-close-action.conf, under that directory:

sudo gnome-text-editor /etc/systemd/logind.conf.d/lid-close-action.conf

Here also replace gnome-text-editor depends on your Ubuntu edition or desktop environment, or use nano that works in most cases.

3. When file opens, just add following lines and replace ignore with one of suspend, lock, poweroff, hibernate as you need.

[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

Finally, save file. For nano command line text editor, press Ctrl+S to save and Ctrl+X to exit. And, restart computer to apply change.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

28 responses to Change Lid Close Behavior in Ubuntu 24.04 | 22.04 | 20.04

  1. thank you

    Can you write about the save battery in ubuntu 20.04?

  2. Thank you so much for this! I tried two other guides that didn’t work.

  3. useful, thanks

  4. Unfortunately that didn’t work for me.

  5. Connor MacLeod July 31, 2020 at 10:27 pm

    Fantastic! Thank you so very much for this. It worked great!

  6. Thanks for your help!

  7. Life saver! Thanks!!!

  8. This doesn’t work for me.
    On running this command, `systemctl restart systemd-logind.service` ,
    it says failed to restart session.

  9. Isaac Richardson November 2, 2020 at 12:52 pm

    This does not work at all

  10. Thanks, works for my on Thinkpad T480 on Ubuntu 20.10. It’s broke after update from 20.04.
    systemctl restart systemd-logind.service just made logout and couple of glitches after I logged in, I think it’s faster and simplier just to reboot your laptop.

  11. Is it possible only add not to go in airplain mode???

  12. After doing this I’m not able to charge the laptop using the docking station (WDTB19). Any clue how to reverse it?

  13. This worked, but now I am trying to change it back and I am unable to. Any idea why? Thought I could just input the original value. Tried it with the hash and without. No dice.

  14. Thank you so much!!! After months of looking tutorials and changing system parameters successlessly, this post solved my problem in just two steps. (the problem was ubuntu blocking airplane mode on lid close btw)

  15. Closing the lid while running battery automatically sleeps the laptop, once the AC power is plugged in you can connect external monitor and close the lid without any issues. At least that is my experience on – Ubuntu 20.04.3 LTS fresh install.

  16. This worked fine for me on latest Ubuntu 20,
    Thanks, Larry

  17. this worked for me
    thanks ;)

  18. Thanks very much, useful tips

  19. worked thank you so much

  20. Do you have any idea how to only turn the screen off (so leave the laptop running) when the lid is closed?

  21. I also had to modify Upower config, on file /etc/UPower/UPower.conf as follows (yes, this step sounds weird):

    IgnoreLid=true

    ref: https://askubuntu.com/a/1440278/170833

  22. Changed to poweroff and it worked as hoped after restarting.