Preventing Sleep Mode When Closing a Linux Laptop

Recently, I assembled a NAS system using an old laptop and needed to configure it so that the laptop does not enter sleep mode when the lid is closed. Here are the steps I followed:

  1. Edit the logind.conf file with the following command:
    vi /etc/systemd/logind.conf
  2. You will see the following content:

    #HandlePowerKey: Action when the power button is pressed, default is power off
    #HandleSleepKey: Action when the sleep button is pressed, default is suspend
    #HandleHibernateKey: Action when the hibernate button is pressed, default is hibernate
    #HandleLidSwitch: Action when the laptop lid is closed, default is suspend (HandleLidSwitch=lock)

    Note: Change the last parameter of HandleLidSwitch to lock and remove the preceding comment #.

  3. To make the changes take effect immediately, enter the command:
    systemctl restart systemd-logind
  4. Done! The laptop lid will no longer cause it to enter sleep mode.

Leave a Comment