4

I am running Ubuntu GNOME 14.04, using gdm display manager and gnome-shell environment and I need to achieve the following behaviour: after boot, a selected user is automatically logged in, but a password is still needed to access the session. Or in other words, after the user is automatically logged in, the screen is locked immediately.

The user login is specifically needed; it's not about starting a service at boot time (which is achievable with different means).

Is this behaviour possible? If so, how to do it in the most clean and non-hacky way? Changing the display manager or the environment is not an option.

Thanks for any input.

zegkljan
  • 428
  • 7
  • 19

1 Answers1

5

Enable auto login.

Check whether you have installed gnome-screensaver by running following command.

sudo dpkg --get-selections | grep gnome-screensaver

If it is not installed run following command to install gnome-screensaver.

sudo apt-get update && sudo apt-get install gnome-screensaver

Add this command on Startup application.(To open startup application preferences search "Startup applications" on Unity dashboard.

/usr/bin/gnome-screensaver-command -l

enter image description here

This screenshot is a Unity screenshot. But this works on GNOME shell without any modification.

Latest Ubuntu version has a command called loginctl. You can replace startup command with below command and get the same thing done.

loginctl lock-session

dedunu
  • 9,186
  • Needed to install gnome-screensaver, but works like a charm. Thanks! – zegkljan Oct 20 '14 at 10:35
  • 2
    You really want to use command loginctl lock-session nowadays. That will work no matter which screensaver you're using. – Mikko Rantalainen Oct 13 '18 at 11:18
  • @MikkoRantalainen Thanks a lot, I updated the answer. – dedunu Oct 15 '18 at 08:12
  • It seems to take a couple minutes for my Ubuntu to finally get around to running this command. Is there a way to make sure this start up application runs sooner? – E.S. Mar 22 '19 at 05:30
  • On 22.04 with either command, desktop remains unlocked with a notification that says "Unable to lock; Lock was blocked by an application". I had to add a delay to get it to work: sh -c "sleep 15 ; loginctl lock-session" – AgentRev Jul 22 '23 at 22:15