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
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:
echo "$(( SECONDS - start ))"
(( $(duration) > 60 ))
! grep -q "inactive" <<< "$(state)"
until isactive || iscrazy
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
I recommend you run it before the next step
Place it between the startup applications
echo "[Desktop Entry]
Exec=<pathtoscript>" > ~/.config/autostart/screen_lock.desktop
or add manually in "Startup Applications" (
Works with Ubuntu and has been tested on a Pop! _OS 20.04
You have to install the needed packages as
Remember to change
<pathtoscript> with the path to the script you created