loginctl — Manage Sessions and Users with systemd-logind
Practical guide to loginctl: list, lock and terminate systemd-logind sessions and users, and use linger to keep services running without an active login.
loginctl is your interface to the systemd login manager (systemd-logind) and shows you who is currently logged in to your system – across sessions, users and physical seats. You can inspect and lock sessions, terminate stuck logins, and use linger to keep user services running even without an active login. This guide walks you through the commands you actually reach for in everyday administration and troubleshooting, from read-only inspection to the operations that intervene.
Sessions
loginctl list-sessions — List all active sessions.
loginctl list-sessionsloginctl session-status <session-id> — Show detailed status of a session.
loginctl session-status 3loginctl show-session <session-id> — Show properties of a session (machine-readable).
loginctl show-session 3loginctl terminate-session <session-id> — Terminate a specific session (destructive: programs running in the session are killed).
sudo loginctl terminate-session 3loginctl lock-session <session-id> — Lock a session's screen.
loginctl lock-session 3loginctl unlock-session <session-id> — Unlock a session's screen.
loginctl unlock-session 3Users
loginctl list-users — List all logged-in users.
loginctl list-usersloginctl user-status <user> — Show detailed status of a user's sessions.
loginctl user-status adminloginctl show-user <user> — Show properties of a user (machine-readable).
loginctl show-user adminloginctl terminate-user <user> — Terminate all sessions of a user (destructive: unsaved work is lost).
sudo loginctl terminate-user guestloginctl kill-user <user> — Send a signal to all processes of a user (destructive: kills running processes).
sudo loginctl kill-user guestLinger
loginctl enable-linger <user> — Enable linger: user services run even without an active login.
sudo loginctl enable-linger deployloginctl disable-linger <user> — Disable linger: user services stop when the user logs out.
sudo loginctl disable-linger deployloginctl show-user <user> -p Linger — Check if linger is enabled for a user.
loginctl show-user deploy -p LingerSeats
loginctl list-seats — List all seats (physical workstations).
loginctl list-seatsloginctl seat-status <seat> — Show status of a seat.
loginctl seat-status seat0loginctl show-seat <seat> — Show properties of a seat.
loginctl show-seat seat0 Conclusion
loginctl is your window into systemd's session management: list-sessions, list-users and session-status safely show you who is logged in and what is running – ideal for troubleshooting. enable-linger is especially useful: only with it do services started via systemctl --user (a deploy worker or a background job, say) keep running once nobody is logged in anymore. Be careful with the operations that intervene: terminate-session, terminate-user and kill-session/kill-user end running sessions and processes immediately – any unsaved work of the affected users is lost. These commands need sudo, and loginctl only works on systemd-based systems.
Further Reading
- Arch Wiki: systemd/User – user services, linger and the user instance of systemd
- systemd-logind.service (man page) – the official reference for the login manager loginctl talks to
Related Commands
- systemctl – control systemd services and units (including
--userservices) - journalctl – query the systemd journal and inspect session logs
- su – switch users and run commands as another user