Skip to main content
  1. Posts/

Stop Ubuntu Server Sleeping When Laptop Lid Closes

Table of Contents

Introduction
#

If you run Ubuntu Server on a laptop, closing the lid can suspend the system. For home servers and lab machines, this can stop Docker containers, SSH sessions, and scheduled tasks.

This guide shows how to disable lid-close suspend using systemd-logind.


Edit logind Configuration
#

sudo nano /etc/systemd/logind.conf

Find these lines:

#HandleLidSwitch=suspend
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore

Change them to:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

This tells logind to ignore lid-close events on battery, AC power, and when docked.


Apply the Change
#

Restart logind:

sudo systemctl restart systemd-logind

Test Lid-Close Behavior
#

  1. Keep an SSH session open from another device.
  2. Start a continuous ping test:
ping 1.1.1.1
  1. Close the laptop lid for 1 to 2 minutes.
  2. Confirm the server is still reachable over SSH and ping.

If it stays online, the change is working.


Conclusion
#

Your Ubuntu Server laptop will now keep running when the lid is closed. This is useful for self-hosted services, lab environments, and always-on workloads.