408. Screen lock
The screen lock is Plasma’s: KWin’s screen locker, kscreenlocker, covers every output and asks for the account’s password before the session shows again. This page covers when it locks by itself, the PAM stacks it checks a password against, locking by hand, and what to do when the lock screen will not unlock. Locking, idle and power together are described in Locking, idle and power; this page gives the procedures.
Installation
| Port | Provides |
|---|---|
| kscreenlocker | The locker KWin runs, its greeter kscreenlocker_greet, the Screen Locking page of System Settings, and the PAM stacks kde and kde-fingerprint |
| kwin | Holds the locked state: while the session is locked KWin shows only the greeter, and a greeter that dies leaves the screen locked rather than open |
| powerdevil | The idle timers that dim and blank the screen, and the lock before a suspend |
| elogind | PrepareForSleep, on which the locker locks before the machine sleeps, and loginctl lock-session |
| pam | unix_chkpwd, the setuid helper that reads /etc/shadow for a process that is not root |
| fprintd | The fingerprint service the kde-fingerprint stack asks; see Fingerprints, FIDO keys and smart cards |
The locker runs inside the session and is not a service. The live medium and an installed system lock alike, except that neither the live medium nor a virtual machine locks on a timer.
Configuration
When the screen locks
KDOS’s defaults, from fs/usr/share/kdos/xdg/kscreenlockerrc:
[Daemon]
Autolock=true
Timeout=10
LockGrace=5
LockOnResume=true
[Greeter][LnF][General]
alwaysShowClock=true
showMediaControls=true
[Greeter][Wallpaper][org.kde.image][General]
Image=file:///usr/share/wallpapers/KDOS-Bone/
fs/usr/share/kdos/xdg/kscreenlockerrc, lines 23–34
So the screen locks after 10 minutes without input, a key or a move within 5 seconds of the lock unlocks with no password, and the machine always resumes locked. The screen itself dims at 5 minutes and turns off at 15 on mains power, which is PowerDevil’s, from fs/usr/share/kdos/xdg/powerdevilrc:
[AC][Display]
DimDisplayIdleTimeoutSec=300
TurnOffDisplayIdleTimeoutSec=900
fs/usr/share/kdos/xdg/powerdevilrc, lines 17–19
In a virtual machine and on the live medium the screen does not lock on a timer. The session puts an extra settings directory first in XDG_CONFIG_DIRS there (/usr/share/kdos/xdg-vm in a virtual machine, /usr/share/kdos/xdg-live on the live medium), for two reasons:
- seen through a virtual machine’s viewer, a desktop that locked itself looks like one that stopped;
- the live session logs in by itself, so nobody trying the system has typed the live account’s password,
kdos.
Meta+L and the lock on resume still lock there, and kdos unlocks them. The timeout of 0 is what makes System Settings → Screen Locking read “Never”, rather than the 10 minutes it would otherwise inherit. From fs/usr/share/kdos/xdg-vm/kscreenlockerrc:
[Daemon]
Autolock=false
Timeout=0
fs/usr/share/kdos/xdg-vm/kscreenlockerrc, lines 20–22
A person’s choices on System Settings → Screen Locking are saved in ~/.config/kscreenlockerrc and outrank all of these.
The PAM stacks
The greeter checks a password against /etc/pam.d/kde and, in parallel, a fingerprint against /etc/pam.d/kde-fingerprint, from ports/core/kde/kscreenlocker/build.sh:
install -vdm755 "$PKG/etc/pam.d"
cat > "$PKG/etc/pam.d/kde" << "EOF_PAM"
# Begin /etc/pam.d/kde
auth include system-auth
account include system-account
# End /etc/pam.d/kde
EOF_PAM
cat > "$PKG/etc/pam.d/kde-fingerprint" << "EOF_PAM"
# Begin /etc/pam.d/kde-fingerprint
auth required pam_fprintd.so
account include system-account
# End /etc/pam.d/kde-fingerprint
EOF_PAM
chmod 644 "$PKG/etc/pam.d/kde" "$PKG/etc/pam.d/kde-fingerprint"
ports/core/kde/kscreenlocker/build.sh, lines 28–42
system-auth runs pam_unix, which, in a process that is not root, asks unix_chkpwd to check the password against /etc/shadow. Smart card, face and FIDO unlocking are compiled out.
An autologin that starts locked
On the encrypted single-account machine whose install asked for autologin, the session starts behind the lock screen: the autologin’s own configuration directory carries LockOnStart=true. See Login and autologin.
Usage
Locking by hand
Meta+L, or the Lock button in the Application Launcher’s Leave row.- From a terminal:
loginctl lock-session, which asks elogind to lock the current session, orqdbus6 org.freedesktop.ScreenSaver /ScreenSaver Lock.
Unlocking
Type the account’s password and press Enter, or touch an enrolled finger. The greeter shows the clock and the media controls; Switch User goes back to SDDM’s greeter for another account while this session stays locked.
Changing when the screen locks
- System Settings → Screen Locking.
- Set Lock screen automatically to the minutes you want, or turn it off; set Delay before password required for the grace; turn Lock after waking from sleep on or off.
- Apply. It applies at once.
Keeping the screen on for a while
The battery and brightness applet in the system tray has Manually block sleep and screen locking, which holds both until it is turned off. A video player or a presentation does the same while it plays, through the inhibition interface; the applet lists who holds one.
Tips
- The lock is drawn by KWin, so a lock screen that seems frozen is a greeter that died. KWin keeps the session locked and offers to restart the greeter; press a key or move the pointer.
- The lock screen’s wallpaper follows the accent:
kdos thememoves it to the chosen accent’s wallpaper while it still names a KDOS one. loginctl lock-sessions, as root, locks every session on the machine, for example before handing a shared machine over.
Troubleshooting
The correct password is refused. Log in on tty2 with the same password. A refusal there too means the password is not what you think. If tty2 accepts it, check the helper:
ls -l /usr/sbin/unix_chkpwd # -rwsr-xr-x root: setuid
sudo grep -E 'kscreenlocker|unix_chkpwd' /var/log/messages | tail
Without the setuid bit no process but root can check a password, and every unlock fails.
The lock screen will not go away. Unlock it from another console:
Ctrl+Alt+F2, log in as the same user.loginctl list-sessionsto find the locked graphical session’s id, thenloginctl unlock-session <id>.Ctrl+Alt+F1.
The screen does not lock after the timeout. Something holds an inhibition: open the battery and brightness applet to see which application. A virtual machine and the live medium do not lock on a timer by design; echo "$XDG_CONFIG_DIRS" starts with an overlay there.
The machine resumes unlocked. LockOnResume was turned off on the Screen Locking page; turn Lock after waking from sleep back on.
Known gaps
- Known gaps: the desktop’s open items
See also
- Power management: idle dimming, suspend and the lid
- Login and autologin: the greeter, and an autologin that starts locked
- Fingerprints, FIDO keys and smart cards: enrolling a finger
- Security model: the setuid helpers and PAM