5

I have recently updated to 20.04 and now when I suspend, either waiting for a long time, closing the lid or manually suspending, the screen does not automatically lock. I've tried setting the 'lock on suspend' in the setting but nothing changed.

I am running lightdm with unity greeter, if that helps.

1 Answers1

3

For anyone who has come looking for a solution to a similar problem, here's how I solved it.

Credit to pszafer here: https://bbs.archlinux.org/viewtopic.php?id=191797

So it turns out that indeed it is due to lightdm that ubuntu was disabling the automatic lock. To get around thata I wrote the following script that calls dm-tool to lock the screen, saved in the home directory:

#!/bin/sh
export XDG_SEAT_PATH="/org/freedesktop/DisplayManager/Seat0"
dm-tool lock

Note that you Seat0 might be different for you. You can check that by running

dm-tool list-seats

Then I put this script saved at /etc/systemd/system/dmlock.service:

[Unit]
Description=DM Lock before sleep
Before=sleep.target

[Service]
ExecStart=/home/path/to/previous/script

[Install]
WantedBy=sleep.target

Then you need to enable the service using

systemctl enable dmlock.service

You can also test if it is working with

systemctl start dmlock.service
  • Does the lock work, if you try different Ctrl-Alt-function keys? – jarno May 12 '20 at 07:15
  • @jarno you can set a custon short cut to rum dm-tool lock to lock the screen, but the usual lock screen short cuts are disabled by ubuntu when you use a different dm. – Christian Fares May 15 '20 at 01:50
  • 2
    Nice workaround but lock screen really should be working correctly by default. I'm surprised its not fixed already! – i9pp0 May 25 '20 at 12:33
  • 1
    Always remember to make the script executable with chmod 755 /home/path/to/script/. I forgot this myself at my first attempt :-). – ksyrium Dec 22 '22 at 10:19