I also ended up asking myself the same question in 2020 (Fedora 32, Gnome 3.36 on X11), since the current version of GDM appears to have a very annoying bug: My Gnome session freezes up, but I still can move the mouse cursor. Just google for "gnome freeze except mouse". Once I switched to SDDM these issues do not occur anymore. However, now I need to take care about the screen lock by myself, as this is usually what GDM does for you.
Luckily, we still have gnome-screensaver around:
sudo dnf install gnome-screensaver
To make it autostart, we can use the .desktop file from the answer by the user aseq
sudo nano /etc/xdg/autostart/gscreenlock.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Gnome screen saver
TryExec=/usr/bin/gnome-screensaver
Exec=/usr/bin/gnome-screensaver
NoDisplay=true
NotShowIn=XFCE;KDE;
Comment=Allows screen locking in gnome
Once gnome-screensaver is running, locking the screen via Super+L works out
of the box. I didn't figure out how to change the current lock screen background,
but I'm also fine with the default one.
Now the really tricky thing is to make gnome-screensaver lock the screen after resuming from suspend/hibernate. Combining pieces of information from here and here I managed to get the following working.
This is the script for calling gnome-screensaver before suspending
sudo nano /opt/lock-screen.sh
#!/bin/bash
#https://github.com/mikebdotorg/gnome-screensaver-lock/blob/master/lock
# have to grab the newest gnome-session so we don't grab gdm's d-bus session information by mistake
gsPid="`pgrep -n gnome-session | egrep '^[0-9]+$'`"
if [ -z "$gsPid" ]
then
echo "gnome-session does not appear to be running" 1>&2
exit 1
fi
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS="`grep -z ^DBUS_SESSION_BUS_ADDRESS= /proc/${gsPid}/environ | cut -f2- -d=`"
/usr/bin/gnome-screensaver-command --lock; sleep 2
sudo chmod +x /opt/lock-screen.sh
And this is the systemd unit that executes our script
sudo nano /etc/systemd/system/lock-on-wakeup.service
[Unit]
Description=Lock screen when waking up
Before=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
[Service]
User=vs
Type=oneshot
ExecStart=/opt/lock-screen.sh
[Install]
WantedBy=sleep.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
sudo systemctl enable lock-on-wakeup.service
sudo systemctl daemon-reload
You can then use systemctl suspend
to test that it works as expected. Hope it helps.
Ctrl + Alt + L
. Does it work?Lock screen
?Ctrl + L
- but that doesn't do anything.