The Sudden Sleep
Like most modern operating systems, Ubuntu Linux is configured to automatically suspend (put to sleep) your laptop the moment you close the lid. This is a sensible default for saving battery life when you throw your laptop into a bag. However, this automatic suspension is incredibly frustrating if you use your laptop as a desktop replacement. If you have your laptop plugged into power, connected to an external monitor, keyboard, and mouse, closing the lid to clear your desk space will instantly kill your session, disconnect your SSH terminals, and turn off the external monitor.
Configuring the Lid Switch Action
To keep your system running in a “clamshell” mode and stop Ubuntu from automatically suspending when you close the laptop lid, you must override the default power management daemon settings.
For modern Ubuntu systems using systemd, this requires a quick terminal edit, as the GUI settings often lack this specific toggle. Open a terminal (Ctrl+Alt+T). You need to edit the `logind.conf` file with root privileges. Type sudo nano /etc/systemd/logind.conf and press Enter (provide your password). Look through the file for the line that reads #HandleLidSwitch=suspend. You need to uncomment this line (remove the `#` symbol at the beginning) and change the value. Modify the line to read exactly: HandleLidSwitch=ignore. Save the file by pressing Ctrl+O, Enter, and then Ctrl+X to exit nano. Finally, to apply the changes immediately without rebooting, restart the login daemon by typing sudo systemctl restart systemd-logind (note: this will briefly restart your graphical session).