How to auto-lock desktop after Auto-Login?

Hello!

My system automatically boots and logs in to the desktop environment as user ‘user’ (member of ‘sudoers’ group), i.e. without any user intervention.

How can I set up the system so that it does as described above and then automatically (i.e. also without any user intervention) locks the screen?

Thanks for your help! :blush:

What DE are you using? Different DEs have different methods for invoking the Lock Screen.

Also, out of sheer curiosity, why not just disable auto login to get essentially the same effect?

1 Like

I use LightDM and dm-tool lock to manually lock the session, but I want that this happens automatically after the user has been auto-logged in.

Can I use a script for this? Where would I have to store it, e.g. in /usr/bin/, and how would I have this script executed after auto-login? I must ensure that the script is not executed after manual login, of course. :wink:

I think what you want is just disabling the auto login. Or is there a specific reason you absolutely need the auto login?

I run deCONZ with GUI on that device and want to ensure that it runs after power failure and restart without any manual intervention.

Fair enough. In that case (since I’m assuming you’re not really interested in the security implications), you could set the auto-lock timer to something like 1s. Not sure where to set that in LightDM, but I’m sure google will help you out there.

There is in theory the option to create a user systemd service (https://superuser.com/questions/1037466/how-to-start-a-systemd-service-after-user-login-and-stop-it-before-user-logout) that executes a script once a user-session is established, you could make that depend on your GUI application (which would then also be run as a service). No idea what your security requirements are, the solution will heavily depend on that.

A universal (or DE-agnostic) option is to use a bash script that locks your screen with a DE-agnostic screenlocker like betterlockscreen. Set the timer to whatever you want in the script.

XScreenSaver

I added the last line to /etc/xdg/lxsession/LXDE-pi/autostart, and that was all I needed:

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@dm-tool lock

It auto-locks the session after auto-login. :grinning:

For reference:
https://forums.raspberrypi.com/viewtopic.php?t=280482
https://forums.raspberrypi.com/viewtopic.php?t=294014

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.