4

I enabled "lock on suspend" (sleep). This works fine, however this will also trigger when I hibernate the laptop. When I resume from hibernation, I have to enter two passwords: On the cryptsetup screen to unlock the drive and on the login screen.

Is there a way to not lock on hibernate (systemctl hibernate), but still lock on sleep?


I am on Ubuntu 20.04 (but I am flexible and will switch to any version, if that solves this problem).

cscharf
  • 41

1 Answers1

1

You could put together a script that you would use when hibernating, such that it first sets

gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false

and then hibernates. Then use another script that runs after resume (you do not need here to be selective about executing only upon resume from hibernation, as it could run upon resume from suspend as well, in which case it will have no effect), which sets

gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend true

I am not certain about the exact locations where to check/place for these scripts. This idea is analogous to this script /lib/systemd/system-sleep/toggle-lock, which might be very close to what you need

#!/bin/sh
set -e

if [ "$2" = "hibernate" ]; then case "$1" in pre) XINPUTUSER=$(who | grep :0 | sed 's/([a-z])./\1/') DISPLAY=:0.0 su - $XINPUTUSER -c "gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false" ;; post) XINPUTUSER=$(who | grep :0 | sed 's/([a-z])./\1/') DISPLAY=:0.0 su - $XINPUTUSER -c "gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend true" ;; esac fi

Notes:

  1. This asks about a similar issue, but with a much more specific target sequence of actions. Options there might be useful for you.
  2. The link above uses pm, while Ubuntu 20.04 uses systemd. I am not certain they are "incompatible".
  3. Overall, I could look for the details to come up with a tentative step-by-step list of instructions. I often do that, but I also personally consider it is appropriate for an answer to promote a solution method, and the interested OP to take the method and fill in the gaps with further tinkering.

Related

  1. Correct way to execute a script on resume from suspend
  2. https://unix.stackexchange.com/questions/423524/script-that-is-executed-after-resuming-from-hibernation
  3. https://www.addictivetips.com/ubuntu-linux-tips/run-scripts-and-commands-on-suspend-and-resume-on-linux/