When switching from GDM to LightDM, the screen locking no longer works. Even putting it into hibernate / suspend, the session isn't locked. The cause lies in the fact that GDM has screen locking built in, where LightDM doesn't.
This means another 'helping' package is required to get screen locking to work with LightDM again. Below you'll find examples getting it to work with three different methods:
Lock screen in LightDM using gnome-screensaver
Earlier versions of GDM used this gnome-screensaver package to provide the locking feature, but recent versions have it removed because GDM3 has the locking built in. Nonetheless, LightDM has working support for gnome-screensaver.
1. Installing gnome-screensaver
The deamon won't be started until the computer has been started (because the package generate an autostart item). Optionally it can by manually invoked for testing:
2. Invoking light-locker when hybernate / sleep
This works right out of the box, no configuration needed. However it must be enabled under Settings → Power
.
3. Setting up Super + L shortcut
This also works right out of the box, taking into account you set up the keyboard shortcut correctly. See Settings → Devices → Keyboard
and check the Lock Screen
shortcut.
Lock screen in LightDM using i3lock
The i3lock package is a utra lightweight and minimal screen locker, therefore it's very much in line with LightDM's philosophy of being… Erm, lightweight.
1. Installing i3lock
2. Invoking i3lock when hibernate / suspend
Before your system goed into sleep mode, a script will call i3lock, as described, create a a file /etc/systemd/system/lockbeforesleep@user.service
, replacing
with your username. And fill it with the following content:user
Then, the service needs to be enabled, and optionally tested:
3. Setting up Super + L shortcut
Either use the Settings-app
and navigate to Devices → Keyboard
to create a new shortcut calling the following command: /usr/bin/i3lock -i /home/user/Pictures/your_wallpaper.png
or use the commands below to automate the process:
# Clear current screensave command, to free up Super + L
dconf write /org/gnome/settings-daemon/plugins/media-keys/screensaver "''"
# Create new entry
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/binding "'<Super>l'"
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/name "'LightDM i3lock'"
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/command "'/usr/bin/i3lock -i /home/user/Pictures/your_wallpaper.png'"
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"
Lock screen in LightDM using light-locker
1. Installing light-locker
2. Invoking light-locker when hibernate / suspend
Before your system goed into sleep mode, a script will call i3lock, as described, create a a file /etc/systemd/system/lockbeforesleep@user.service
, replacing
with your username. And fill it with the following content:user
Then, the service needs to be enabled, and optionally tested:
sudo systemctl enable lockbeforesleep@user.service
sudo systemctl daemon-reload
# Optionally test the service
systemctl suspend
3. Setting up Super + L shortcut
Either navigate to Settings → Devices → Keyboard
to create a new shortcut calling the following command: dm-tools lock
or use the commands below to automate the process:
# Clear current screensave command, to free up Super + L
dconf write /org/gnome/settings-daemon/plugins/media-keys/screensaver "''"
# Create new entry
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/binding "'<Super>l'"
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/name "'LightDM light-locker'"
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/command "'dm-tools lock'"
dconf write /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"
That's it, hit Super + L and see if it works!
References
- https://unix.stackexchange.com/questions/86221/how-can-i-lock-my-screen-in-gnome-3-without-gdm
- https://www.reddit.com/r/gnome/comments/9klvej/is_there_a_way_to_get_the_screen_to_lock_with/
- https://forum.manjaro.org/t/how-to-fix-lock-screen-after-changing-gdm-to-lightdm/62751
- https://askubuntu.com/questions/632384/lock-screen-from-root-shell