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 23.10 with default GNOME desktop environment.
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 24.04, replace gedit
in command with gnome-text-editor
or nano
command line text editor depends on your desktop environment.
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 different lid close action when running on power supply.
For choice, you can also uncomment ‘HandleLidSwitchExternalPower=suspend
‘ by removing # at its beginning, and change the value to lock, ignore, poweroff, or hibernate.
So the rule in step 2.) only works when your laptop is running on battery. While, this step will take effect when running on AC power supply.
4.) Finally apply changes by running command (For old 14.04 with init, use sudo restart systemd-logind
instead):
systemctl restart systemd-logind.service
For Ubuntu 22.04 and higher, the command will log you out, and break next login. So, you may just restart your computer instead to apply change.
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.
thank you
Can you write about the save battery in ubuntu 20.04?
Just install TLP and thank me layer!
Thank you so much for this! I tried two other guides that didn’t work.
useful, thanks
Unfortunately that didn’t work for me.
Almost solves my issue.
Fantastic! Thank you so very much for this. It worked great!
Thanks for your help!
Life saver! Thanks!!!
This doesn’t work for me.
On running this command, `systemctl restart systemd-logind.service` ,
it says failed to restart session.
This does not work at all
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.
Is it possible only add not to go in airplain mode???
After doing this I’m not able to charge the laptop using the docking station (WDTB19). Any clue how to reverse it?
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.
Thank You
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)
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.
This worked fine for me on latest Ubuntu 20,
Thanks, Larry
this worked for me
thanks ;)
Thanks very much, useful tips
worked thank you so much
Do you have any idea how to only turn the screen off (so leave the laptop running) when the lid is closed?
for me, HandleLidSwitch=ignore did exactly what you want
I hope it works differently than the “Do nothing” option in Gnome Tweaks, which one leaves the screen on which is terrible for many reasons, from screen life to energy/battery life.
PS: I am on Ubuntu 22.10, might be a kernel bug also.
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
Changed to poweroff and it worked as hoped after restarting.