8

It might be a [duplicate] but none of the answers I found work for me.

brieucdug@sildenafil:~$ uname -a ; gnome-shell --version ; lightdm --version
Linux sildenafil 5.4.0-31-generic #35-Ubuntu SMP Thu May 7 20:20:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
GNOME Shell 3.36.2
lightdm 1.30.0

I don't know from when, I suspect it comes with the installation of lightdm, my screen doesn't lock with timeout nor on suspend (lid closed, this is how I first found out the issue). I confirm my computer does go in suspend when I close the lid.

brieucdug@sildenafil:~$ gsettings list-recursively  | grep -i -E "screen.*lock|lock.*screen"
com.canonical.unity.settings-daemon.peripherals.touchscreen orientation-lock false
org.gnome.settings-daemon.peripherals.touchscreen orientation-lock false
org.gnome.desktop.privacy usb-protection-level 'lockscreen'
org.gnome.desktop.lockdown disable-lock-screen false
org.gnome.desktop.notifications show-in-lock-screen true
org.gnome.Vino lock-screen-on-disconnect false
org.gnome.desktop.screensaver ubuntu-lock-on-suspend true
org.gnome.desktop.screensaver lock-enabled true
org.gnome.desktop.screensaver lock-delay uint32 0

And a screen in my settings... screen lock settings

NB : I already tried to edit the /etc/systemd/logind.conf but I am open to suggestions

Lorenz Keel
  • 8,905
  • I can confirm that my desktop rig has the same issues and I assume the reason is the lightdm. I use lightdm because multiseat with gdm3 was acting funny, and as soon as I installed (and used) lightdm, screensaving stopped working :( IIRC there was a popup message by Gnome warning me from that, but that popup disappeared quickly and I could not fully read it. – MariusSiuram May 31 '20 at 06:52

3 Answers3

6

Save the following as /etc/systemd/system/lock-on-wakeup.service:

[Unit]
Description=Lock screen when waking up
Before=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

[Service] Type=oneshot ExecStart=dm-tool lock ; sleep 2 Environment=XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0

[Install] WantedBy=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

Then activate this with:

sudo systemctl enable lock-on-wakeup.service

sleep 2 in ExecStart= should prevent the system to go to sleep before the lock screen activation is in effect (which would result in the user's desktop being visible for a split second after waking up, before the lock screen actually activates). If this is not sufficient, increase the value. (Run sudo systemctl daemon-reload after any modifications.) There might be more proper solutions than sleep to make sure the lock screen is in effect.

Helpful resources were especially:

Thomas W.
  • 480
1

I solved creating a service using loginctl:

Check if your system has loginctl:
sudo /bin/loginctl lock-sessions

1 - Create the file:
sudo gedit /etc/systemd/system/lock.service

2 - Fill it with:

[Unit]
Description="Make extra sure to lock the screen when suspending"

[Service] Type=oneshot User=root ExecStart=/bin/loginctl lock-sessions

[Install] WantedBy=suspend.target

3 - Afterwards, type:

sudo systemctl daemon-reload
sudo systemctl enable lock.service

Here are more details on how to lock when suspend:
https://makandracards.com/makandra-orga/166759-ensure-screen-lock-on-suspend

danilo
  • 1,385
0

I noticed that my screen wasn't locking at all, neither with super + L nor CLI options from How do I lock the desktop screen via command line? and then I managed to get super + L working as per After upgrading to ubuntu 20.04 Lockscreen not working with:

gsettings set org.gnome.desktop.lockdown disable-lock-screen false

Once that was done, suspend would also lock the screen. This happened on Ubuntu 23.10, GDM display manager.