15

My computer only has a single user that is used for normal log in.

On boot, it would be convenient of the system would log in that user automatically, and then optionally, lock the screen, such as by launching a password protected screen saver.

Suggestions?

user50849
  • 492
  • 2
  • 7
  • 20

6 Answers6

7

Set your user for automatic login in System Settings -> User Accounts -> Automatic Login (you will need to press the "unlock" button and enter your password before you can change the automatic login setting).

The command gnome-screensaver-command -l will cause the screen to be immediately locked, which can probably be added to your autostart items.

Using gedit (or other text editor of choice), create /home/USERNAME/.config/autostart/screen_lock.desktop with contents:

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

And hopefully it will automatically login and then lock the screen.

chronitis
  • 12,367
6

I'm using Ubuntu 18.04.1 LTS with Gnome 3.28.2 and this worked for me. Set a user to auto-login, either via the GUI or by editing /etc/gdm3/custom.conf. On the desktop, click on Show Applications, type in "Start" and you'll see the "Startup Applications Preferences", open it, click on Add, give it whatever Name and Comment you'd like and put the following in the Command input:

dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock

On re-boot, it will auto-login and immediately lock the screen for whatever user you set up in /etc/gdm3/custom.conf.

3

This is an old question but this is the best option:

Set your user for automatic login

echo "AutomaticLoginEnable=True" | sudo tee -a /etc/gdm3/custom.conf
echo "AutomaticLogin=$(whoami)" | sudo tee -a /etc/gdm3/custom.conf

Or change in Settings -> Users -> Automatic Login

Write a script

gnome-screensaver can do the job but we have to make shure its available when the machine runs the code. To get it, create a script with the following:

#!/bin/bash

duration() { echo "$(( SECONDS - start ))" }

iscrazy() { (( $(duration) > 60 )) }

state() { /usr/bin/gnome-screensaver-command -q }

isactive() { ! grep -q "inactive" <<< "$(state)" }

start=$SECONDS

/usr/bin/gnome-screensaver &

until isactive || iscrazy do /usr/bin/gnome-screensaver-command -l done

echo "$(state) and it took $(duration) seconds"

This will attempt to lock the screen until it succeeds or spends more time than usual.

Make shure that execution is enabled on file permissions with

chmod +x <pathtoscript>

or checking "Allow executing file as program" by right-clicking and going to Properties -> Permissions

I recommend you run it before the next step

Place it between the startup applications

echo "[Desktop Entry]
Type=Application
Name=Lock Screensaver
Exec=<pathtoscript>" > ~/.config/autostart/screen_lock.desktop

or add manually in "Startup Applications" (gnome-session-properties)

Notes

Works with Ubuntu and has been tested on a Pop! _OS 20.04

You have to install the needed packages as gnome-screensaver

Remember to change <pathtoscript> with the path to the script you created

3

What you ask is almost a normal setup. During installation you get asked to insert a password and can choose to have that user log in automatically. This image shows the checkbox as off (You can not use automatic log in with an encrypted home).

enter image description here

After install you can still set this at the accounts settings:

enter image description here

The screen lock is by default set to ask for a password. Have a look at this topic for more information: How do I disable the screensaver/lock? on where to find it. The setting where you can do this looks like this:

enter image description here

It is about not setting the lock but you just have to set it the other way.

Rinzwind
  • 299,756
  • 1
    With this setup the user will be logged on automatically with their computer unlocked vulnerable to attacks. What OP is asking is how to login and lock the screen automatically at the same time after boot. – denysonique Dec 16 '13 at 20:12
  • @denysonique he said "optionally lock the screen" so this is a user discussion that can not be automated ;) – Rinzwind Dec 16 '13 at 20:18
0

There were a lot of answers to this already old question but none of them where satisfactory for me. Here is how to do it using a systemd service.

Set your user for automatic login

This can be easyly done by changing it in Settings -> Users -> Automatic Login

Create a Systemd service

Create a file in /home/<username>/.local/share/systemd/user/ that is named in the format<name>.service containing the following code:

[Unit]
Description=Lock screen on login
After=graphical.target gnome-session.target
Requires=gnome-session.target

[Service] Type=dbus BusName=org.gnome.ScreenSaver ExecStart=dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver or> [Install] WantedBy=graphical.target

The crux here is the After= and Requires= to be set to the display manager that you are using, here it is gnome-session for instance.

Now all you need to do is run systemctl --user enable <name>.service to enable the service and lock the screen on login. It can be easily disabled by running systemctl --user disable <name>.service

  • doesn't work for me (Ubuntu 20.04) dbus-send[10722]: Must use org.mydomain.Interface.Method notation, no dot in "or>" systemd[1362]: lock.service: Main process exited, code=exited, status=1/FAILURE systemd[1362]: lock.service: Failed with result 'exit-code'. systemd[1362]: Failed to start Lock screen on login. – Riki_tiki_tavi Oct 08 '21 at 05:28
0

For those of you that use a KDE based system, follow these instructions:

Automatic Login Required First

This can be easily done by changing it in Settings -> Startup and Shutdown -> Login Screen -> Automatically Login

Screen Saver Command for KDE

This is the Qt command you would add to startup; as an application:

qdbus org.kde.ksmserver /ScreenSaver org.freedesktop.ScreenSaver.Lock

Note: Settings -> Startup and Shutdown -> Autostart -> Add Application

ZaxLofful
  • 101
  • 4