How to Change Lid Close Behavior in Ubuntu 20.04

Last updated: May 14, 2020 — 14 Comments

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, while it suspends Ubuntu by default.

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!

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

1.) Open terminal (press Ctrl+Alt+T on Gnome) from your system application menu. When it opens, run command:

sudo gedit /etc/systemd/logind.conf

Type user password (no asterisk feedback) and hit Enter. For Ubuntu server without UI, use nano text editor instead.

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.
  • HandleLidSwitch=poweroff – shutdown.
  • HandleLidSwitch=hibernate – hibernate Ubuntu.

For automatic hibernate, you have to test if it works properly via command:

sudo systemctl hibernate

3.) Finally apply changes by running command:
(Save your works before running the command, it may restart your session)

systemctl restart systemd-logind.service

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.

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 notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected]

14 responses to How to Change Lid Close Behavior in Ubuntu 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.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.