Have you ever connected your Ubuntu laptop to an external monitor, SSH session, server, or other device and discovered that everything stops working as soon as you close the laptop lid?
By default, Ubuntu may suspend the system when the laptop lid is closed. This is useful for normal laptop use because it saves battery and reduces power consumption. However, it can be inconvenient when you want your laptop to continue running with the lid closed.
For example, you may want to use your Ubuntu laptop as:
- A home server
- An SSH server
- A development machine
- A media server
- A Docker/Kubernetes node
- A machine connected to an external monitor
- A remote desktop system
- A background download or automation system
Fortunately, Ubuntu allows you to change the lid-close behavior through systemd-logind.
What Happens When You Close the Laptop Lid?
On a typical Ubuntu installation, closing the lid triggers an action handled by systemd-logind.
The default behavior is commonly:
HandleLidSwitch=suspendThis means:
When the laptop lid is closed, suspend the system.
We can change this behavior to:
HandleLidSwitch=ignoreThis tells Ubuntu:
When the lid is closed, do nothing.
The laptop will therefore continue running even though the physical lid is closed.
Method: Disable Suspend on Lid Close
Step 1: Open the Terminal
Press:
Ctrl + Alt + TAlternatively, search for Terminal from the Ubuntu application menu.
Step 2: Open the systemd Login Configuration
Run:
sudo nano /etc/systemd/logind.confYou will be asked for your administrator password.
The file contains configuration options controlling various login and power-management behaviors.
Step 3: Find the Lid Switch Setting
Look for:
#HandleLidSwitch=suspendThe # means that the line is commented out.
Change it to:
HandleLidSwitch=ignoreIf the line already exists without #, simply change:
HandleLidSwitch=suspendto:
HandleLidSwitch=ignoreYour configuration should look like:
[Login]
HandleLidSwitch=ignoreIf [Login] already exists, don't create another [Login] section.
What About External Power?
If you primarily use your laptop while it is connected to a charger, you can also configure the external-power behavior:
HandleLidSwitchExternalPower=ignoreThis can be useful when the laptop is being used as a workstation or server while connected to AC power.
For example:
[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignoreWhat About a Dock or Docking Station?
If you use your Ubuntu laptop with a docking station, you may also encounter the docked-state setting.
You can configure:
HandleLidSwitchDocked=ignoreA configuration for a laptop that should remain running regardless of lid/power state could therefore be:
[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignoreHowever, you don't necessarily need all three settings. Start with HandleLidSwitch=ignore and add the others only if your particular setup requires them.
Step 4: Save the Configuration
If you're using Nano:
- Press Ctrl + X
- Press Y to confirm saving
- Press Enter
Your configuration has now been saved.
Step 5: Apply the Changes
You can restart systemd-logind:
sudo systemctl restart systemd-logindAlternatively, and often more conveniently on a desktop/laptop system, reboot Ubuntu:
sudo rebootA reboot ensures that the new configuration is loaded cleanly.
Important: Restarting
systemd-logindcan affect active graphical/login sessions on some systems. If this is an important workstation or remote machine, a planned reboot may be the safer option.
Test the Configuration
After Ubuntu starts again, close the laptop lid.
If everything is configured correctly, Ubuntu should remain running instead of suspending.
You can test this by:
- Connecting through SSH
- Checking a running process
- Accessing a web server
- Connecting through Remote Desktop
- Monitoring a Docker container
- Checking a file transfer
- Accessing an external monitor
For example, from another computer:
ssh username@ubuntu-ipIf the connection continues working after closing the lid, your Ubuntu machine is successfully remaining active.
Useful Configuration Examples
Normal Laptop — Suspend on Lid Close
The default behavior can be represented by:
HandleLidSwitch=suspendThis is appropriate if you want the laptop to save power when you close the lid.
Laptop Server — Keep Running
For a laptop being used as a server:
HandleLidSwitch=ignoreThis prevents lid closure from triggering suspend.
Laptop Used as a Docked Workstation
If you frequently connect the laptop to a charger, monitor and dock:
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignoreWhy Would You Want to Disable Lid Sleep?
There are several practical situations where this configuration is useful.
1. Using an External Monitor
You may want to close the laptop lid and use only your external display.
Without changing the lid behavior, Ubuntu may suspend the laptop.
2. Running a Home Server
An old laptop can make an excellent low-power home server.
You could run:
- Ubuntu Server
- Docker
- Kubernetes
- PostgreSQL
- Web applications
- File servers
- Home automation
- Media services
Disabling lid suspension allows the laptop to continue operating with the lid closed.
3. Remote Access
If you use:
- SSH
- RDP
- VNC
- RustDesk
- Other remote-management tools
you may want the machine to remain available even when the lid is closed.
4. Long-Running Jobs
Developers and administrators may run:
Docker containersBuild jobsData-processing tasksMachine-learning workloadsor other long-running processes.
Suspending the laptop could interrupt or pause these workloads.
Check Whether the Configuration Is Active
You can inspect the current configuration with:
grep -i "HandleLidSwitch" /etc/systemd/logind.confYou may see:
HandleLidSwitch=ignoreYou can also inspect the effective logind configuration:
loginctl show-logindOn systems where the command exposes the relevant properties, look for values such as:
HandleLidSwitch=ignoreImportant: Disabling Sleep Is Not the Same as Disabling the Screen
Changing:
HandleLidSwitch=ignoredoesn't necessarily mean that the display will remain active.
The laptop can continue running while its internal display is turned off because the lid is closed.
This is generally desirable when using the machine as a server or with an external monitor.
Important Power and Heat Considerations
Keeping a laptop running with the lid closed isn't always ideal.
The display may turn off, but the CPU, storage, networking hardware and other components can continue operating.
On some laptop designs, closing the lid can also reduce airflow around the keyboard or cooling system.
Therefore:
Make sure the laptop has adequate ventilation.
Avoid placing a running laptop:
- Inside a closed cabinet
- Under blankets
- On a soft bed
- In an area where air vents are blocked
If you're converting an old laptop into a permanent server, consider placing it on a hard, well-ventilated surface.
What If It Still Suspends?
If changing logind.conf doesn't work, don't immediately assume the configuration is wrong.
Several factors can influence power management, including:
- Desktop-environment settings
- GNOME power-management behavior
- Docking state
- External power configuration
- systemd-logind inhibitors
- Distribution-specific configuration
- Other power-management software
First verify your configuration:
grep -i "HandleLidSwitch" /etc/systemd/logind.confThen reboot and test again.
You can also check the system journal:
journalctl -u systemd-logindThis can help identify whether systemd-logind is processing the lid event.
Is It Safe to Disable Lid Suspend?
Generally, yes, if you understand the consequences.
The configuration does not disable the laptop's ability to suspend manually. It changes what happens specifically when the lid is closed.
You should, however, consider:
- Battery consumption
- Heat generation
- Ventilation
- Accidental overheating
- Whether the laptop is connected to AC power
- Whether you actually need the machine running continuously
For a laptop being used as a home server, keeping it connected to AC power and ensuring good ventilation is usually more appropriate than relying on battery power.
Quick Command Summary
Edit the configuration
sudo nano /etc/systemd/logind.confSet lid close to do nothing
HandleLidSwitch=ignoreOptional external-power setting
HandleLidSwitchExternalPower=ignoreOptional docked setting
HandleLidSwitchDocked=ignoreRestart logind
sudo systemctl restart systemd-logindOr reboot
sudo rebootCheck your configuration
grep -i "HandleLidSwitch" /etc/systemd/logind.confFinal Thoughts
Ubuntu is flexible enough to turn an ordinary laptop into a surprisingly capable server or always-on Linux workstation.
If you frequently use your Ubuntu laptop with an external monitor, SSH, Remote Desktop, Docker, Kubernetes or other long-running services, changing the lid-close action from:
suspendto:
ignorecan make the machine much more convenient to operate.
The key configuration is simply:
HandleLidSwitch=ignoreJust remember that "ignore" means Ubuntu will not automatically suspend because you closed the lid. It does not mean the machine consumes no power or generates no heat.
For a server-style setup, always prioritize proper ventilation, reliable power and appropriate security.
One-Line Takeaway
Want your Ubuntu laptop to keep running after you close the lid? Set
HandleLidSwitch=ignorein/etc/systemd/logind.conf, then reboot and test it.
Tags:
Ubuntu, Ubuntu Linux, Ubuntu Tutorial, Linux Tutorial, Linux Tips, Ubuntu Tips, Laptop Lid Close, Disable Sleep Ubuntu, Disable Suspend Ubuntu, Ubuntu Lid Settings, systemd logind, systemd-logind, logind.conf, Linux Power Management, Ubuntu Power Management, External Monitor Ubuntu, Ubuntu Server, Laptop as Server, SSH Server Ubuntu, Remote Desktop Ubuntu, Linux Server, Ubuntu 24.04, Ubuntu 25.04, Ubuntu 26.04
Hashtags:
#Ubuntu, #UbuntuLinux, #Linux, #LinuxTips, #UbuntuTips, #UbuntuTutorial, #LinuxTutorial, #LinuxServer, #UbuntuServer, #Systemd, #SystemdLogind, #LinuxPowerManagement, #DisableSleep, #DisableSuspend, #LaptopServer, #RemoteDesktop, #LinuxAdmin, #DevOps, #SRE, #OpenSource
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......