This short tutorial shows how to change the action in Ubuntu 20.04 when the laptop lid is closed (eg power off, hibernate, do nothing or lock), but Ubuntu by default It is suspended.
The Dconf Editor has an option to change the action to take when the laptop lid is closed by AC or power, but it doesn’t work!
As far as I know, you can edit the logind.conf file to change the action. And it should work on all Ubuntu desktops, servers and flavors.
1.) Open Terminal from the system application menu (press Ctrl + Alt + T in Gnome). Once open, run the following command.
sudo gedit /etc/systemd/logind.conf
Enter the user password (without asterisk feedback) and press Enter. For Ubuntu server without UI,
nano A text editor instead.
2.) When the file opens, find the line # HandleLidSwitch = suspend and change it to one of the following:
- HandleLidSwitch = lock – Lock when the lid is closed.
- HandleLidSwitch = ignore – do nothing.
- HandleLidSwitch = poweroff – shutdown.
- HandleLidSwitch = hibernate – hibernate Ubuntu.
For auto-hibernation, you should use commands to test for proper functioning.
sudo systemctl hibernate
3.) Finally, run the command to apply the changes.
(Save your work before executing the command; the session may be restarted)
systemctl restart systemd-logind.service
Note that you have to perform the previous steps each time you change an action. Also, Gnome Tweaks’s “Pause when laptop lid is closed” option no longer works before commenting (adding # at the beginning) to the line /etc/systemd/logind.conf.