Create a (password) lock on suspend

Intro: I like it to have my desktop locked when my laptop goes into suspend (after for example an inactive timeout has reached).
To achieve this I crafted up the following files/settings/service

  1. Install i3lock (default available on mabox)
  2. Create a lock picture on which you state that the user needs to enter his/her password (make sure it has the correct size for your (full)screen as i3lock will not resize it.
    Save this picture in a folder (for this example we place it in /usr/share/backgrounds and name it pwd.png [png is mandatory])
  3. Create a new file named suspend@.service in /etc/systemd/system
    Place the following lines inside this file
[Unit]
Description=User suspend actions
Before=sleep.target

[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -i /usr/share/backgrounds/pwd.png
ExecStartPost=/usr/bin/sleep 1

[Install]
WantedBy=sleep.target
  1. Now enable the service by running the command “sudo systemctl enable suspend@$USER.service” (if this doesn’t work then replace $USER with your username (without $))
  2. Reboot
  3. Test by running the command “systemctl suspend”. If all went well your picture should show and you can start typing your password and press enter to unlock your desktop.
2 Likes

I think similar effect can be achieved by command:

betterlockscreen --suspend

Betterlockscreen can’t be forked so it’s not working in a suspend service (or I’m doing something horribly wrong :slight_smile: )
But is that works it would be much nicer than my dirty service! :+1:

I think you’re right.

I don’t use suspend/hibernate at all
I just checked this command quickly from the console :wink: