Lock Your Screen from the Terminal (loginctl lock-session)

Use loginctl lock-session to lock the current desktop session, or lock-suspend to lock and suspend in one step.

LinuxlockdesktopsessionsecurityLow risk
Run `loginctl lock-session` to lock your desktop screen immediately.

01Command

Command
$ loginctl lock-session

02What it does

The command sends the session lock signal to whatever screen locker your desktop uses (GNOME Screensaver, KDE screen locker), so it behaves exactly like pressing Super+L. `loginctl lock-suspend` locks and then suspends the machine in one step — useful as a custom laptop-lid or keybinding action. On XFCE use `xflock4` instead, and `loginctl list-sessions` shows which sessions are active.

03Risk

RiskLow risk
Requirementssystemd with a desktop session that honors lock signals: GNOME and KDE both do. On XFCE use `xflock4`; with xscreensaver installed use `xscreensaver-command -lock`.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • loginctl(1) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    Evidence: loginctl lock-session activates the session lock, and lock-suspend locks before suspending; the desktop session's screen locker responds to the lock signal.

Last verified: 2026-09-18 · Category: System & Settings

06Related solutions