Categories: Ubuntu

How to Modify Laptop Close Behavior in Ubuntu with HandleLidSwitch

The logind.conf login manager configuration file on Ubuntu 20.04 Linux system can be used to adjust the lid closure behavior. On Ubuntu, this approach can be used to turn off the display when the lid is closed; it can also be used to change the behavior of the laptop’s lid when it is closed. Ubuntu suspends by default when the laptop lid is locked. To change the behavior of the lid on Ubuntu, we will modify the logind.conf file. Because the default configuration is defined during compilation, the configuration is only required when deviations from the defaults are required.
Sponsored

As a guide to the administrator, the primary configuration file in /etc/systemd/ comprises of commented-out entries indicating the defaults. Editing this file or generating drop-ins can be used to build local overrides. Programs can download drop-ins under /usr/ when they need to change the setup. The files in /etc/ are designated for the local administrator, who can utilize this logic to alter the supplier configuration files. Because the main configuration file took priority over package drop-ins, drop-ins must be used to override them. . We will configure the default lid close action in Ubuntu 20.04 LTS in this tutorial.

Method to Modify Laptop Close Behavior in Ubuntu with HandleLidSwitch

To go through it, you must have sudo rights and any Linux edition installed on your operating system. We have installed and set up Ubuntu 20.04, which will be used to carry out our tasks. Log in to the Ubuntu 20.04 Linux system and go to the activity area, where a search bar will appear. To get a command-line shell terminal, write the word “terminal” into it. When the terminal app appears, click it to open it. Enter the following command to modify the default login manager configuration file for Ubuntu 20.04 Linux System:

$ sudo gedit /etc/systemd/logind.conf

You will be asked to enter a sudo user password. Enter the password to proceed further. Once the file is up and working, you should see something as shown in the beneath screenshot.

You can view several options that are shown in the screenshot. We are going to explain few fields that are essential for users.

  • HandleLidSwitch=lock – Whenever the lid will be closed, Ubuntu 20.04 system will be locked automatically.
  • HandleLidSwitch=ignore – As the flag –ignore signifies that there will be no specific output after this instruction.
  • HandleLidSwitch=poweroff – Whenever the lid will be closed, Ubuntu 20.04 system will be locked shut down automatically.
  • HandleLidSwitch=hibernate – Whenever the lid will be closed, Ubuntu 20.04 system will be locked hibernate automatically.

We have another option as HandleSuspendKey=Suspend. We are going to use it in the following way.

$ sudo systemctl suspend

As we have used “sudo” keyword, so upon execution, the system will prompt the user to enter the password. As soon as the password has been entered, the system will be automatically suspended as you can see from the attached screenshot.

Sponsored

We can now apply all the changes that we have made by the execution of the following command in the terminal of the Ubuntu 20.04 system.

$ Sudo systemctl restart systemd-logind.service

Because we used the “sudo” keyword, the system will request the user for a password when it is executed. As you will see in the attached image, as soon as the password is provided, the system will prompt you for the logged-in user’s password for authentication purposes.

This is how all the changes will be saved in the system.

Conclusion

In this guide, we have explained to you the main concept of logind.conf login manager configuration file on Ubuntu 20.04 Linux system. Also, we have shown you how you can modify laptop or computer close behavior in Ubuntu 20.04 Linux system with HandleLidSwitch.

Ubuntu Server Admin

Recent Posts

Open design: the opportunity design students didn’t know they were missing

What if you could work on real-world projects, shape cutting-edge technology, collaborate with developers across…

2 days ago

Anbox Cloud 1.28.0 is now available!

Enhanced Android device simulation, smarter diagnostics, and OIDC-enforced authentication The Anbox Cloud team has been…

2 days ago

83% of organizations see value in adopting open source, but report major gaps in security and governance

A new Linux Foundation report reveals how organizations worldwide are adopting, using, and perceiving open…

3 days ago

Everything you need to know about FIPS 140-3 on Ubuntu | Videos

FIPS 140 is a highly demanding security standard that’s mandatory for almost all high-security and…

4 days ago

A CISO’s preview of open source and cybersecurity trends in 2026 and beyond

Open source has come a long way. Recently I was watching a keynote address by…

1 week ago

Canonical Kubernetes officially included in Sylva 1.5

Sylva 1.5 becomes the first release to include Kubernetes 1.32, bringing the latest open source…

1 week ago