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

How to Install Google Cloud BigQuery Python client library on Linux

In this article, we will see how to Install Google Cloud BigQuery Python client library…

2 days ago

Wallpaper Contest for Xfce 4.20 open for voting

Nov 15,2024 Wallpaper Contest for Xfce 4.20 open for voting The submission phase for the…

2 days ago

Canonical announces the first MicroCloud LTS release

MicroCloud 2.1.0 LTS is now available, expanding the number of Canonical infrastructure solutions with a…

2 days ago

Join Canonical in Paris at Dell Technologies Forum

Canonical is thrilled to be joining forces with Dell Technologies at the upcoming Dell Technologies…

3 days ago

Bringing automation to open source 5G software at Ubuntu Summit 2024

In today’s massive private mobile network (PMN) market, one of the most common approaches to…

4 days ago

Ubuntu Weekly Newsletter Issue 865

Welcome to the Ubuntu Weekly Newsletter, Issue 865 for the week of November 3 –…

6 days ago