491

I would like closing the laptop lid to be a no-op. How can I do that?

Jorge Castro
  • 71,754
badp
  • 12,372

16 Answers16

572

For 13.10 - 24.04:

To disable Ubuntu doing anything closing the laptop lid:

  1. Open the /etc/systemd/logind.conf file in a text editor as root, for example,

    sudoedit /etc/systemd/logind.conf
    
  2. If HandleLidSwitch is not set to ignore then change it:

    HandleLidSwitch=ignore
    

    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.

  3. Restart the systemd daemon (be aware that this will log you off) with this command:

    sudo systemctl restart systemd-logind
    

    or from 15.04 onwards:

    sudo service systemd-logind restart
    

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:

# Ubuntu 18.04
sudo apt-get install gnome-tweak-tool

Ubuntu 20.04+

sudo apt-get install gnome-tweaks

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.

karel
  • 114,770
Tasos Koutoumanos
  • 5,752
  • 1
  • 13
  • 2
  • 76
    This didn't work for me. What finally solved it for me was setting IgnoreLid=true in /etc/UPower/UPower.conf – Kimble Apr 02 '14 at 14:10
  • 7
    HandleLidSwitch=hibernate if you want your laptop to hibernate instead of doing nothing. – Salman Apr 18 '14 at 01:08
  • 8
    Aternative: sudo apt-get install dconf-tools, open dconf Editor application, go to org => gnome => setting-deamon => plugins => power – pbaranski Apr 26 '14 at 18:21
  • 6
    Worked for me on 14.04. – kroiz Jun 13 '14 at 07:36
  • Confirmed: Worked for me on Xubuntu 15.05 in both boot-to-console and boot-to-gui modes. – John Jun 16 '15 at 19:23
  • On Ubuntu 15.04, I got "restart: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused" from the systemd command. – CPBL Jun 20 '15 at 13:30
  • @abrasadera's approach is the only one that works on the latest Ubuntu as of time of this comment. – Maxim V. Pavlov Jul 11 '15 at 15:01
  • Probably worth noting that THIS works, unlike the documentation, and obvious method of doing it through System Settings->Power. – Eric Blade Jul 13 '15 at 15:19
  • 3
    I restart it using sudo service systemd-logind restart – Iacchus Nov 17 '15 at 14:29
  • This worked with Ubuntu MATE 14.04 (without gedit-part - with Ubuntu MATE you may wish to use pluma or nano), I only needed to uncomment and edit mentioned line. Now I can shut down my laptop without it going to sleep during shutdown, if lid is closed. This can easily happen when doing a hasty shutdown (closing lid too early) or when using external screen. Using gconf-editor had no help with the "sleep during shutdown"-problem, because different config hits in when control is switched off from userspace (at least with MATE).

    @Tasos, why you use -H with this?

    – F-3000 Nov 30 '15 at 09:33
  • this works too on debian 8.4, jessie. I think that is good to know for some. However, restart the service by sudo service systemd-logind restart(@Kassius) – vertikalist Apr 08 '16 at 10:28
  • You should use gksudo and not sudo when opening a graphical app as root! – Delorean Jun 01 '16 at 15:12
  • It works well on Ubuntu 16.04. Works as workaround for https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1566302 Lots of thanks! – corretge Jun 09 '16 at 11:22
  • Worked for Ubuntu 17.04 with Gnome as well – czerasz Jun 01 '17 at 06:25
  • The solutions didn’t work for me on Ubuntu 17.04. Using @Kimble’s suggestion required calling service upower restart after changing UPower.conf and it worked. – kleinfreund Jul 19 '17 at 05:55
  • from 15.04 onwards: sudo systemctl restart systemd-logind – Wojciech Domalewski Dec 18 '17 at 23:26
  • For those who have LED keyboards, what command is for light up the keyboard again when laptop lid is open? – falconR Dec 28 '17 at 16:53
  • This worked for me on budgie-desktop 10.4 (Ubuntu 16.04.3 LTS 64-bit). – David 'the bald ginger' Jan 24 '18 at 14:21
  • 3
    This worked for me on Ubuntu Server 18.04. – Carsten Führmann May 19 '18 at 21:12
  • Worked! Now I have a place to set my coffee. Xubuntu 18.04 on Dell laptop using dual 15" USB screens. The laptop screen is always blank anyway. – Bob Brunius Dec 17 '19 at 15:01
  • Worked on 19.10 – Philip Rego Jan 12 '20 at 03:18
  • Works for 18.04 32-Bit with a ssh-server installation too. – MadMike Jan 26 '20 at 21:15
  • 1
    I want my computer to only blank my screen when I close the lid.

    I set the lid-close-[ac|battery]-action to "blank" in Gnome's dconf Editor. Seems to work until I re-open lid. What happens then is that it takes 1 sec, then it locks my PC. Then it lags 1-5 more seconds, and suspends my PC. Am I missing anything here?

    – MahNas92 Mar 16 '20 at 11:06
  • works welll on ubuntu 18.04.4 LTS 64bit desktop. gnome-tweak is easier for changing behavior. log-off and log-in required to make effect. – Hongsoog May 15 '20 at 07:47
  • ohh, I installed tweak and I forgot that app :) thank you – nobjta_9x_tq Jul 11 '20 at 06:50
  • 1
    Work well for 20.04 64bit desktop. Thanks for your answer. – sondt87 Oct 09 '20 at 01:02
  • The gnome tweak change did not alone work for me. The change that worked was with the Upower conf. – anoopjohn Jul 01 '21 at 21:01
  • 1
    Is there a solution if you have gdm stopped on Ubuntu 20.04? I've tried all solutions above, and it works but only when gdm is running. When I close the lid after I stopped gdm my laptop goes into standby again instead of doing nothing (resp. turning the screen off..). – Don Dadda Aug 24 '21 at 10:04
  • How do we prevent sleep, but still have the screen turn off with the lid closed? – kennyB Nov 24 '21 at 21:54
  • Worked partially for me on Debian 11. I also had to set HandleLidSwitchExternalPower=ignore to keep my laptop awake while it's connected to power. – Dullson Jan 20 '22 at 15:16
  • 1
    Works perfectly on Ubuntu 22.04. Thanks for the fix mister, highly appreciated! Hope to see some GUI tool in future that handles this type of functionality, because this seem like a core configuration thing! – Игор May 31 '22 at 10:06
  • Thank you, it finally worked on 22.04. Not the gnome-tweaks solution, that only disables suspend when I'm logged in, not on the login screen. – user1768761 May 18 '23 at 11:51
74

For 11.04 and earlier:

Do nothing when laptop lid is closed (helpful when an external monitor is connected):

  • Alt + F2 and enter this: gconf-editor
  • apps > gnome-power-manager > buttons
  • Set lid_ac and lid_battery to nothing

alt text

OR

1.When on AC Power, do nothing when laptop lid is closed:
gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_ac nothing

2.When on Battery Power, do nothing when laptop lid is closed:
gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_battery nothing


Blank screen when laptop lid is closed (preferable when no external monitor is connected):

  • System > Preferences > Power Management
  • On AC Power (On Battery Power) > Actions
  • When laptop lid is closed: Blank screen

alt text

OR

1.When on AC Power, blank screen when laptop lid is closed:
gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_ac blank

2.When on Battery Power, blank screen when laptop lid is closed:
gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_battery blank

Sid
  • 10,533
71

Ubuntu 15.10 - Ubuntu 20.04

TL;DR: Add IgnoreLid=true to /etc/UPower/UPower.conf

  1. Open a terminal and run:

     sudoedit /etc/UPower/UPower.conf
    
  2. Change IgnoreLid to IgnoreLid=true

  3. Save and exit the editor.

  4. Restart the UPower service with:

     service upower restart
    
Error404
  • 7,440
mrfromage
  • 819
43

For 11.10 - 12.04:

You can select "Do Nothing" in the power settings. Open the dash (super key), search for "power" and then select the correct option in the dropdown. Note that closing the lid will actually turn off the screen though plus any external monitors:

enter image description here

If you move the mouse then any connected monitors will power back up with the laptop closed. This will then become the primary monitor.

This might either have been removed at some point, or it requires some hardware support which is not available in all systems: Since 16.04, I don't have 'when the lid is closed' options in power settings as there have been reports that it was not visible on Ubuntu 21.04.

Jorge Castro
  • 71,754
7

11.04 and previous versions

Copying 1st given answer from: http://ubuntuforums.org/showthread.php?t=1319921&highlight=close+laptop+lid

In a terminal (Applications-->Accessories-->Terminal), type: gconf-editor

Navigate to apps-->gnome-power-manager-->buttons and set lid_ac and/or lid_battery to "nothing" (without the quotes).

alt text

Pavlos G.
  • 8,844
7

I have 14.04.1 LTS, Trusty Tahr.

What doesn't worked for me:

  1. Open the /etc/systemd/logind.conf file in a text editor as root, for example,

    sudo -H gedit /etc/systemd/logind.conf
    

    Add a line HandleLidSwitch=ignore (make sure it's not commented out!),

    Restart the systemd daemon with this command:

    sudo restart systemd-logind
    
  2. Edit gConf

    When on AC Power, do nothing when laptop lid is closed:

    gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_ac nothing
    

    When on Battery Power, do nothing when laptop lid is closed:

    gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_battery nothing 
    

What worked for me:

Setting IgnoreLid=true in /etc/UPower/UPower.conf

Fynn
  • 338
  • Working at Xubuntu 14.04.3 i386. Xubuntu have utility Power manager but settings for closing lid not worked for me. This is registered bug? – Vitaly Zdanevich Aug 28 '15 at 23:36
6

Let us create a script that works on all versions

#!/bin/bash

PLEASE FEEL FREE TO CHANGE THE SCRIPT

Ubuntu 16.04 [PLEASE COMPLETE]

sed -i '/HandleLidSwitch/d' /etc/systemd/logind.conf >/dev/null 1&>2 echo 'HandleLidSwitch=ignore' >> /etc/systemd/logind.conf >/dev/null 1&>2

Ubuntu 14.04 [PLEASE COMPLETE]

sed -i '/IgnoreLid/d' /etc/UPower/UPower.conf >/dev/null 1&>2 echo 'IgnoreLid=true'>> /etc/UPower/UPower.conf

[PLEASE COMPLETE ]

gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_ac [PLEASE COMPLETE ]

gconftool-2 -t string -s /apps/gnome-power-manager/buttons/lid_battery nothing [PLEASE COMPLETE ]

RESTART SERVICES

service upower restart service systemd-logind restart

Pablo Bianchi
  • 15,657
user123456
  • 2,378
3

There is a bug with some laptops and monitors that makes Ubuntu not honor the "do nothing" setting when the laptop's lid is closed. I have not been able to find a complete solution, but maybe there is something to do with this link where they hint at this file : /etc/default/acpi-support and using:

gconftool-2 -t string /apps/gnome-power-manager/buttons/lid_ac -s "blank"
gconftool-2 -t string /apps/gnome-power-manager/buttons/lid_battery -s "blank"
Ramon Suarez
  • 1,841
3

For Saucy:

Edit /etc/systemd/logind.conf and set HandleLidSwitch=lock to lock the screen on lid close (but not suspend), or HandleLidSwitch=ignore to not even lock the screen.

This is due to an upstream GNOME change. See GNOME bug 687277 for the rationale for this change.

Robie Basak
  • 15,670
  • Does ubuntu use systemd? – Khurshid Alam Oct 16 '13 at 19:38
  • systemd is now many things. Ubuntu does not use systemd's init ("pid 1"), but it does use components that were formerly independent but are now absorbed into the systemd source, such as udev. So you will see mentions of the systemd name on an Ubuntu system, but that does not mean that its init system has suddenly changed. – Robie Basak Oct 17 '13 at 08:14
3

You can easily disable the lid lock feature by clicking the System Settings icon in the Launcher/Task bar, and then clicking on Brightness & Lock.

From there, you flip the Lock switch to the off position, and un-check the "Require my password when wakening from suspend." check-box.

enter image description here

Another thing you have to watch for if you also plan on setting up hibernation (suspend-to-disk) is whether or not your system has a large enough swap partition to actually go into hibernation. Hibernation is different than suspend, but sometimes people like to set up the hibernation feature while they are configuring suspend.

You can also go over your Power settings, so they don't suspend the system when the lid is close. You can do this in System Setting -> Power.

enter image description here

SunnyDaze
  • 1,396
2

12.04

In System Settings, open Brightness & Lock. On that page, uncheck the checkbox at the bottom that says, "Require my password when waking from suspend."

Kelley
  • 33,062
2

11.04 and previous versions

you can also go to system->preferences->power management

near bottom of the window you will find a dropdown where you can select what your system does when lid is closed

binW
  • 13,034
2

I like to suspend my laptop sometimes, and other times I like to keep it going for long times like a server (do nothing when I close the lid). I use Debian, and here's my simple script to do either one on the fly without rebooting:

# run this in the as the same user (or root) that xwindow is using

# test for required parameter --> empty not allowed
if [ "$1" == "" ]; then
    echo "Please provide true or false"
    echo "True means keep running when lid is closed"
    echo "False means suspend the computer when lid is closed"
    exit;
fi

# "running true" means keep running even if the lid is closed
if [ "$1" = "true" ]; then
    gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing
    gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action nothing
fi


# "running false" means suspend the computer!
if [ "$1" = "false" ]; then
    gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action suspend
    gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action suspend
fi

# if "echo" is supplied as a param, just show the current settings
if [ "$1" = "echo" ]; then
    gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action
    gsettings get org.gnome.settings-daemon.plugins.power lid-close-battery-action 
fi

# restart gnome to make changes effective
/etc/init.d/gdm3 restart
Patrick
  • 21
  • 3
1

For 12.10:

Edit /etc/UPower/UPower.conf and add IgnoreLid=true to the bottom.

This method no longer works in Saucy. I am unsure about 13.04.

Robie Basak
  • 15,670
  • Works on 15.04 64 bit after issuing systemctl restart upower. – KcFnMi Sep 09 '15 at 16:36
  • 1
    /etc/UPower/Upower.conf IgnoreLid=true on ubuntu 14.04 use to work. after the 3.13 kernel roll out it not longer works anymore –  Jan 16 '16 at 17:48
0

So... I tried all the possible solutions listed here, still had the problem. But it turned out to a pretty silly reason.

Well, I wonder why the answerers here didn't mention the part. It's a very basic Linux trick uncommenting is. But hey sometimes there could be some human error because we're not a scripting language or something, right??

So, do the following.

$ sudo nano /etc/systemd/logind.conf

Change the #HandleLidSwitch=suspend part to

HandleLidSwitch=ignore

So the change is as follows.

- #HandleLidSwitch=suspend
+ HandleLidSwitch=ignore
0

Adding an solution not previously listed:

For me, I want my laptop to stay on, but only when it's on A/C or docked. If there's no external power, I want the laptop to suspend as expected when the lid is shut. So my solution (Ubuntu 20.04 and newer) was as follows:

  • Create the add-in confdir for logind config (via manpage), and edit the add-in config no-suspend-on-ac.conf:
sudo mkdir -p /etc/systemd/logind.conf.d && \
    sudoedit /etc/systemd/logind.conf.d/no-suspend-on-ac.conf
  • Contents of no-suspend-on-ac.conf
[Login]
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

HandleLidSwitch remains at it's default behaviour, but with external power (direct or via a dock), shutting the lid will be ignored.

Samveen
  • 180
  • 10