How to Change Lid Close Action in Ubuntu 18.04 LTS

In Ubuntu 18.04 Gnome desktop, there’s no option in Settings utility for configuring laptop lid close actions. And Gnome Tweaks only offer a switch to enable / disable ‘Suspend when laptop lid is closed’.

For those who want it automatic shutdown, hibernate, or do nothing when laptop lid is closed, here’s how to do it by hacking on the configuration file.

1. Open terminal by pressing Ctrl+Alt+T or searching for “Terminal” from start menu. When it opens, run command:

sudo gedit /etc/systemd/logind.conf

Type in your password (no visual feedback while typing due to security reason) when prompts and hit Enter to continue.


2. When the files opens, uncomment the line #HandleLidSwitch=suspend by removing # in the beginning, and change the value to:

  • HandleLidSwitch=poweroff, shutdown / power off when lid is closed.
  • HandleLidSwitch=hibernate, hibernate when lid is closed (need to test if hibernate works).
  • HandleLidSwitch=ignore, do nothing.
  • HandleLidSwitch=suspend, suspend laptop when lid is closed.

Save the file and finally restart the Systemd service to apply changes via command:

systemctl restart systemd-logind.service


In addition:

1. Previous steps do not add shutdown or hibernate options in the Power settings utility, but directly do the action when you close the laptop lid.

2. For some laptops, the hibernate function might not work. Run test command:

sudo apt install pm-utils && sudo pm-hibernate

After your computer turns off, switch it back on. Did previous opened applications re-open? If hibernate doesn’t work, check if your swap partition is at least as large as your available RAM.

About ml

ml is a part time stay-at-home dad who've been using Ubuntu Desktop for a few years. He writes in the free time and wishes to share some useful tips with Ubuntu beginners and lovers.


  1. Thanks so much for the post.Really thank you! Great.

  2. Thanks for the tip.

    I’ll leave this question here in case anyone can help:
    Is there a way to differentiate what happens depending on the notebook being on battery power or plugged when closing the lid?

    Thank you.

    • The version of systemd used by ubuntu does not handle “HandleLidSwitchExternalPower” message. This means that neither systemd nor gnome can differentiate between lid events with power connected and disconnected

  3. Hi, thanks for this post! I have a related question: when the lid closes, I’d like it to lock, so that when I open it again, it asks for my password. Is there a similar way to do that?

  4. This worked perfectly, thank you! I wanted to have this so when i remoted into my laptop it wouldn’t time out.

    many thanks!

  5. the fact that this is so difficult to do for normal users is exactly why people don’t want to use ubuntu

    • this isn’t difficult

      • But it’s completely undiscoverable. (I spent 10 minutes looking for the option before taking to Google.) It’s frustrating that this kind of thing is still necessary for such a basic customization. This is why people scoff at “this is the year of the Linux desktop” comments. (And I say this non-ironically as someone who wrote those type of comments for 20 years ago.)

  6. This worked for me on Ubuntu Server 18.04! Thank you

  7. Thanks for the article, it worked on my Ubuntu 18.04.

    `sudo systemctl hibernate` also checks if hibernate works.

Leave a Reply

Your email address will not be published. Required fields are marked *