To disable automatic suspend when closing the laptop lid in Linux, you’ll need to modify the /etc/systemd/logind.conf file. Specifically, you’ll change the HandleLidSwitch setting from suspend to either ignore (for no action) or lock (to lock the screen).
Here’s how to do it:
- Open the file: Use a text editor with sudo privileges (e.g.,
sudo nano /etc/systemd/logind.conf). - Locate the line: Find the line
HandleLidSwitch=suspend(it might be commented out with a#). - Modify the setting:
- To disable suspend: Remove the
#(comment) and changeHandleLidSwitch=suspendtoHandleLidSwitch=ignore. - To lock the screen: Remove the
#and changeHandleLidSwitch=suspendtoHandleLidSwitch=lock.
- To disable suspend: Remove the
- Save the changes: Save the file (Ctrl+X, Y, Enter in nano).
- Restart the service: Run
sudo systemctl restart systemd-logind.serviceto apply the changes.
After this, closing the lid should no longer trigger automatic suspend and either lock the screen or do nothing, depending on your choice.