How to Stop Ubuntu Linux from Automatically Suspending When the Lid is Closed

The Laptop Server Dilemma

If you are running Ubuntu Linux on a laptop, closing the physical lid will immediately force the operating system into a deep suspend (sleep) state. This is the intended behaviour for normal users trying to save battery life while travelling. However, many Linux users repurpose old laptops to act as home servers, media centers, or network-attached storage (NAS). If you want to close the lid and shove the laptop onto a closet shelf while it continues to run your Docker containers and serve files, the automatic suspend feature renders the machine entirely useless.

How to Disable Suspend on Lid Close via Systemd

To keep your Ubuntu laptop running at full power with the lid closed, you must modify the core systemd login manager configuration file using the terminal.

1. Open your terminal application (or SSH into the machine).

2. Open the systemd logind.conf file in a text editor with root privileges by typing: sudo nano /etc/systemd/logind.conf

3. Scroll down through the file until you find a line that says #HandleLidSwitch=suspend.

4. Delete the # symbol at the beginning of the line to uncomment it.

5. Change the word suspend to ignore. The line should now read exactly: HandleLidSwitch=ignore

6. If you want the same behaviour when the laptop is on battery power, find #HandleLidSwitchExternalPower=suspend, uncomment it, and change it to ignore as well.

7. Save the file by pressing Ctrl + O, press Enter, then exit nano by pressing Ctrl + X.

Applying the Changes

For these deep system changes to take effect, you must restart the systemd login service. Be warned: running this command will immediately log you out of your current desktop session, so save any open work first. Type sudo systemctl restart systemd-logind in the terminal and press Enter. Once you log back in, you can safely close your laptop lid, and your Ubuntu machine will continue humming along in the background without dropping its network connections.

Get the best tech tips delivered straight to your inbox.

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