How can I configure my Ubuntu 14.04, logging in using Gnome 3, to lock the screen when I close my laptop lid?

All Settings ► Power only offers Do nothing or Suspend as options when I close the lid.

All Settings ► Brightness & Lock is configured with Lock ON, Lock screen after Screen turns off. It doesn't seem to work.

I've tried editing /etc/systemd/logind.conf to set HandleLidSwitch=lock and rebooting; nothing changed.

  • Having changed nothing, it's now working as expected. headdesk Thank you for the suggestions, I hope they'll be of use to anyone searching for it later. Sep 9, 2014 at 4:47

3 Answers 3


Easy way: after changing


you have to restart the service

sudo systemctl restart systemd-logind
  • 1
    This should be the top answer, simple and effective
    – user689314
    Nov 19, 2017 at 0:26

There may be other simple method available for what you want but you can lock you screen using this script upon closing your lid. I found it on help.ubuntu.com. I am trying to keep it short. For detail explanation you can visit the link.

  • Make the environment variables available for root.

    gedit ~/export_x_info

    and paste the following contets

    # Export the dbus session address on startup so it can be used by any other environment
    sleep 5
    touch $HOME/.Xdbus
    chmod 600 $HOME/.Xdbus
    env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus
    echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus
    # Export XAUTHORITY value on startup so it can be used by cron
    env | grep XAUTHORITY >> $HOME/.Xdbus
    echo 'export XAUTHORITY' >> $HOME/.Xdbus
  • Make it eecutable using

    chmod 700 ~/export_x_info

  • You need to run it on startup. So add it to Startup Applications. Select Startup Programs from Gnome Menu, and click Add.

    Name:<Any name you want>
  • Now you need to edit your /etc/acpi/lid.sh file which catch lid open and close event. Change user_name with your user name

    gksudo gedit /etc/acpi/lid.sh and paste

    /home/your_user/lid_event just after #!/bin/bash. Save and close.

  • Now you need to create a script for close event so that you can lock your screen.

    gedit ~/lid_event and paste the following.

    grep closed /proc/acpi/button/lid/LID0/state  
     if [ $? = 0 ]
     source /home/user_name/.Xdbus
     DISPLAY=:0.0 su user_name -c "gnome-screensaver-command -l"

    Also check for /proc/acpi/button/lid/LID0/state file because LID0 may be LID.

  • Now restart your ACPI using

    sudo /etc/init.d/acpid restart

  • Make sure that the Power Management option for laptop lid closed is set to do nothing


Make sure that in gnome-tweak-tool Suspend when lid is closed is on under power option

Then change HandleLidSwitch=lock in /etc/systemd/logind.conf

after that run sudo systemctl restart systemd-logind to restart service

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .