Keeping a Linux laptop on when the lid is closed


I sometimes use old laptops in my home lab when I want to test anything on Linux, and I prefer to keep them closed so they take up less space. A few quick commands will keep the laptop even on with the lid closed.

Information

Referenced from Man page for logind.conf

Run the following command to edit the login configuration file:

sudo nano /etc/systemd/logind.conf

Look for the following commented lines in the file:

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

What they do:

  • HandleLidSwitch: Lid close behavior while not plugged in.
  • HandleLidSwitchExternalPower: Lid close behavior while plugged in.
  • HandleLidSwitchDocked: Lid close behavior while docked.

Let’s assume you want the laptop to stay on no matter what when the lid is closed, we’ll uncomment and edit all three lines, telling Linux to ignore these events:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

Save the file and reboot for the changes to take effect. After boot, your laptop will always remain on when closed.