How to Stop Ubuntu from Suspending (Going to Sleep) When the Lid is Closed

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.

  1. Open the Terminal (shortcut: Ctrl + Alt + T).
  2. Open the login manager configuration file in a text editor (such as nano) by running the following command:
sudo nano /etc/systemd/logind.conf
  1. Enter your password when prompted.
  2. Scroll down through the file until you find the line that reads:
#HandleLidSwitch=suspend
  1. You need to uncomment this line (remove the # symbol) and change the value from suspend to ignore. The line should now look exactly like this:
HandleLidSwitch=ignore
  1. Save the file by pressing Ctrl + O, then press Enter.
  2. 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.

  1. 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.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.