How to Prevent a Debian Laptop from Sleeping when the Lid is Closed
When converting an old laptop into a headless home server, the default behavior of modern Linux distributions is to suspend or hibernate the system when the lid is closed.
To keep the server running 24/7 while allowing you to physically close the lid, you must configure the system's power management daemon to ignore the lid switch event.
Step-by-Step Guide
1. Edit the logind.conf file
The systemd-logind service controls this behavior. Open its configuration file:
2. Modify the HandleLidSwitch directive
Look for the line that says #HandleLidSwitch=suspend (it is usually commented out by default, meaning it falls back to the default behavior).
Uncomment the line and change the value to ignore:
Note: The hardware will still automatically turn off the screen backlight when the lid is closed to save power, but the OS itself will continue running.
3. Restart the service
For the changes to take effect immediately without a reboot, restart the systemd-logind service:
Idempotent Automation (Bash)
If you are bootstrapping multiple nodes (or want to ensure this is applied automatically in a script like prep-node.sh), use sed to perform the replacement safely: