Why Stop Ubuntu from Sleeping on Lid Close?
By default, when you close the lid of a laptop running Ubuntu Linux, the operating system goes into suspend mode (sleep) to save battery life. However, if you are using your laptop as a home server, a media centre, or if you simply connect it to an external monitor and keyboard, you want the machine to remain fully awake and operational even when the lid is shut.
To change this behaviour, you need to modify the systemd-logind configuration file via the terminal.
How to Disable Suspend on Lid Close in Ubuntu
This process requires root privileges to edit a system configuration file.
- Open the Terminal (shortcut:
Ctrl + Alt + T). - Open the login manager configuration file in a text editor (such as nano) by running the following command:
sudo nano /etc/systemd/logind.conf
- Enter your password when prompted.
- Scroll down through the file until you find the line that reads:
#HandleLidSwitch=suspend
- You need to uncomment this line (remove the
#symbol) and change the value fromsuspendtoignore. The line should now look exactly like this:
HandleLidSwitch=ignore
- Save the file by pressing
Ctrl + O, then pressEnter. - Exit nano by pressing
Ctrl + X.
For the changes to take effect immediately, you must restart the systemd-logind service. Warning: Restarting this service will log you out of your current desktop session, so save any open work first.
- Run the following command to apply the changes:
sudo systemctl restart systemd-logind.service
Once you log back in, you can safely close your laptop lid. Ubuntu will keep running in the background without suspending your active processes or network connections.