6

I am running Ubuntu 20.04 LTS and is trying to set up my system so it will log in my single user automatically but employ a locked screensaver on startup to ensure security.

I have followed the solution here Automated login and screen lock and created the file ~/.config/autostart/screen_lock.desktop with the following contents:

[Desktop Entry]
Type=Application
Name=Lock Screensaver
Exec=gnome-screensaver-command -l

Upon startup I am logged in automatically but I get the desktop message: Unable to lock: Lock was blocked by an application

Running

gnome-screensaver-command -l

manually in the terminal works fine. I have looked in journalctl, but can only seem to find the same error as shown on the desktop: gnome-shell[1518]: error: Unable to lock: Lock was blocked by an application

Besides the screensaver I have im-launc and SSH Key Agent as startup applications, and I have some crontab jobs running a Python and a bash script, but this should all be background stuff and I can't figure out what is causing the problem. I can see other people have lock-screen problems with full-screen applications and virtual machines, but this is right on startup without (as far as I can tell) problematic applications running.

Any ideas to figure out what is causing the issue or workarounds?

UsernameError
  • 61
  • 1
  • 2

2 Answers2

2

If it works from the CLI, then this is probably a race condition, so you could try putting a sleep in front of the command.

I'd try sleep 60;gnome-screensaver-command -l to start with, to make sure that the login processes have all completed. If that works then you can try sleep 1, and then experiment to find a trade off between it working and speed of lock.

Nmath
  • 12,333
lcd
  • 31
  • 1
    It's worth mentioning that in order to put multiple commands like that in the Exec field, you need to do it like this: bash -c "sleep 1;gnome-screensaver-command -l" – gsgx Mar 13 '22 at 11:22
1

I was previously running 18.04 and had this working using Automated login and screen lock but once upgrading to 20.04, ran into the same problem as the OP. The screensaver works when manually triggered via CLI and Super+L, but not after autologin via the autostarter (got the same blocked by application error, or sometimes nothing at all).

Using @lcd's idea, I was not able to get

[Desktop Entry]
Type=Application
Name=Lock Screensaver
Exec=sleep 60;gnome-screensaver-command -l

working with entries in ~/.config/autostart/. It doesn't seem to trigger, with no evidence of it in journalctl.

What did work was autostarting a bash script that called gnome-screensaver-command -l. I tried calling it without the sleep command resulted in the following entries in journalctl, suggesting that @lcd was right in that there some sort of race condition:

Jan 20 14:37:47 PC gnome-screensav[1735]: unable to send message: Timeout was reached
Jan 20 14:37:47 PC gnome-screensav[1735]: Did not receive a reply from the screensaver.

So my current workaround is:

/home/user/.config/autostart/bootscript1.sh.desktop containing:

[Desktop Entry]
Type=Application
Name=Lock Screensaver
Exec=/home/user/keeps/bootscript1.sh

where bootscript1.sh is

#!/bin/bash

sleep 1 gnome-screensaver-command -l

jfslin
  • 21
  • You can avoid the need to create an actual bash script by setting Exec to bash -c "sleep 1;gnome-screensaver-command -l". It's also worth mentioning that while sleep 1 usually works, it occasionally didn't, so if it doesn't work for you try sleep 2 or higher values. – gsgx Mar 13 '22 at 11:24