If you are using GNOME (the default in 18.04+), then you can do this easily without changing system settings by using the "Gnome Tweak Tool". It can be installed from the Ubuntu Software Store (It is called GNOME Tweaks). Or if you prefer the console: sudo apt-get install gnome-tweak-tool
Run it after installing, then under Power, Turn off the setting to do nothing when lid is closed. I tested this on Ubuntu 18.04 and it works.
Actions to take when closing the laptop lid are configured with command gnome-power-preferences (menu: System -> Preferences -> Power management)
You will need to set two options: "When laptop lid is closed" to "Do nothing", and also "Put computer to sleep when inactive for" to "Never" (otherwise the laptop won't sleep automatically when you close the lid, but will soon afterwards because it's inactive). Note that these options have separate values for "AC power" and "Battery power": of course, you'll have to configure the correct one for your case (or both).
*Note: You may have to run the following command for the option to show up:
gconftool-2 --type string --set /apps/gnome-power-manager/buttons/lid_ac "nothing"
(Note that # before a command indicates that it should be run by the superuser, so replace the # with sudo.)
Open logind.conf as root: # vim /etc/systemd/logind.conf and remove the # before HandleLidSwitch=suspend. You can also change the option suspend to hibernate or poweroff
Best Answer
For 13.10 - 20.04.1:
To make Ubuntu do nothing when laptop lid is closed:
Open the
/etc/systemd/logind.conf
file in a text editor as root, for example,If
HandleLidSwitch
is not set toignore
then change it:Make sure it's not commented out (it is commented out if it is preceded by the symbol
#
) or add it if it is missing,Restart the systemd daemon (be aware that this will log you off) with this command:
or, from 15.04 onwards:
See also: Ubuntu Server 13.10 now goes to sleep when closing laptop lid
For GNOME Users:
If you are using GNOME (the default in 18.04+), then you can do this easily without changing system settings by using the "Gnome Tweak Tool". It can be installed from the Ubuntu Software Store (It is called GNOME Tweaks). Or if you prefer the console:
sudo apt-get install gnome-tweak-tool
Run it after installing, then under Power, Turn off the setting to do nothing when lid is closed. I tested this on Ubuntu 18.04 and it works.