What it does
loginctl is a systemd tool that queries and controls the login manager (systemd-logind). It shows who is logged in, what sessions exist, and can terminate sessions/users.
How it works (mechanical)
- Talks to
systemd-logindover D-Bus. - Tracks users, sessions, and seats (seat0 = local console).
- Can terminate a session or user in a controlled way.
- Useful on desktops, multi-user systems, lab servers, and remote access boxes.
10 Practical Examples
# 1) List all active sessions (who is logged in) loginctl list-sessions
# 2) Show sessions for a specific user loginctl list-sessions | grep -i craig
# 3) List users known to logind (active/inactive) loginctl list-users
# 4) Show details for one session (replace 2 with session ID) loginctl show-session 2
# 5) Show user details (replace UID or username) loginctl show-user username
# 6) Terminate a single session (kicks that login only) sudo loginctl terminate-session 2
# 7) Terminate all sessions for a user (kicks user entirely) sudo loginctl terminate-user username
# 8) Lock/unlock a session (desktop systems; may depend on environment) loginctl lock-session 2 loginctl unlock-session 2
# 9) List seats (console seats; seat0 is typical) loginctl list-seats
# 10) Find the session that owns a PID (handy for “who owns this process?”)
loginctl show-session "$(loginctl list-sessions --no-legend | awk 'NR==1{print $1}')" -p Name -p User -p RemoteNotes & Gotchas
- Requires systemd-logind: on non-systemd systems, loginctl won’t exist or won’t work.
- Permission: terminating sessions/users requires root or appropriate polkit permissions.
- SSH sessions: are typically tracked (and can be terminated) but behavior depends on distro/logind config.
- Locking: lock/unlock only applies if a desktop session supports it (GNOME/KDE, etc.).
Historical Context
Before systemd/logind, admins relied heavily on who, w, ps,
and manual process killing. loginctl introduced a structured view of sessions and seats with consistent control hooks.
Modern Equivalent
On systemd systems, loginctl is the native “session controller.”
For broader identity/session analysis, combine it with:
who/w, ps, journalctl, and your directory service tools.
Related Commands
- who, w — logged-in users (classic)
- ps, pkill — process view/control
- systemctl — service manager
- journalctl — logs (who did what and when)
- last — login history