On Ubuntu Change Lid Close Behaviour – Turn Off Screen When Lid Closed

On Ubuntu change lid close behaviour using the logind.conf default login manager configuration file. Using this method on Ubuntu turn off display when lid is closed; change laptop close lid behaviour on Linux Ubuntu Systems.

The logind.conf

The logind.conf is the default login manager configuration file for Linux Ubuntu Systems. This file configures various parameters of the systemd login manager systemd-logind.service. The systemd-logind is a system service that manages user logins. It is responsible for:

* Keeping track of users and sessions, their processes and their idle state
* Creating control groups for user processes
* Providing PolicyKit-based access for users to operations such as system shutdown or sleep
* Implementing a shutdown/sleep inhibition logic for applications
* Handling of power/sleep hardware keys
* Multi-seat management
* Session switch management
* Device access management for users
* Automatic spawning of text logins (gettys) on virtual console activation and user runtime directory management

We will be tweaking the following parameter of the login manager configuration file:

HandlePowerKey=, HandleSuspendKey=, HandleHibernateKey=, HandleLidSwitch= Controls whether logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or suspend. Can be one of ignore, poweroff, reboot, halt, kexec, suspend, hibernate, hybrid-sleep and lock. If ignore logind will never handle these keys. If lock all running sessions will be screen locked. Otherwise the specified action will be taken in the respective event. Only input devices with the power-switch udev tag will be watched for key/lid switch events. HandlePowerKey= defaults to poweroff. HandleSuspendKey= and HandleLidSwitch= default to suspend. HandleHibernateKey= defaults to hibernate.

To edit the default login manager configuration file for Linux Ubuntu Systems, run the following command:


sudo gedit /etc/systemd/logind.conf

Once the file is up and ready; you will get the content similar to the following lines:


# This file is part of systemd. systemd is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Entries in this file show the compile time defaults. You can change settings by editing this file. Defaults can be restored by simply deleting this file. See logind.conf(5) for details.

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=yes
#UserTasksMax=12288

When the file opens, find out the line #HandleLidSwitch=suspend and change it to one of following :

1. HandleLidSwitch=lock – lock when lid closed.
2. HandleLidSwitch=ignore – do nothing.
3. HandleLidSwitch=poweroff – shutdown.
4. HandleLidSwitch=hibernate – hibernate Ubuntu.

Suspend on lid close

In order to trigger suspend on closing the lid, make sure that there is a line in /etc/systemd/logind.conf that reads HandleLidSwitch=suspend, and that it is not commented out (prefixed with #). The default values are:

* HandleLidSwitch=suspend
* HandleLidSwitchDocked=ignore

After making the change to logind.conf, run:


systemctl restart systemd-logind.service

And you are done, after doing so closing the laptop’s lid should cause the laptop to suspend..

If you are running a simple xsession, and want to make sure your screen locks on suspend, you can install the xscreensaver and xss-lock packages, and add the lines to your .xsession-file


xscreensaver &
xss-lock -- xscreensaver-command --lock &

On Ubuntu Change Lid Close Behaviour – Turn Off Screen When Lid Closed originally posted on Source Digit – Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos.