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-sessions

loginctl session-status <session-id> — Show detailed status of a session.

loginctl session-status 3

loginctl show-session <session-id> — Show properties of a session (machine-readable).

loginctl show-session 3

loginctl terminate-session <session-id> — Terminate a specific session (destructive: programs running in the session are killed).

sudo loginctl terminate-session 3

loginctl lock-session <session-id> — Lock a session's screen.

loginctl lock-session 3

loginctl unlock-session <session-id> — Unlock a session's screen.

loginctl unlock-session 3

Users

loginctl list-users — List all logged-in users.

loginctl list-users

loginctl user-status <user> — Show detailed status of a user's sessions.

loginctl user-status admin

loginctl show-user <user> — Show properties of a user (machine-readable).

loginctl show-user admin

loginctl terminate-user <user> — Terminate all sessions of a user (destructive: unsaved work is lost).

sudo loginctl terminate-user guest

loginctl kill-user <user> — Send a signal to all processes of a user (destructive: kills running processes).

sudo loginctl kill-user guest

Linger

loginctl enable-linger <user> — Enable linger: user services run even without an active login.

sudo loginctl enable-linger deploy

loginctl disable-linger <user> — Disable linger: user services stop when the user logs out.

sudo loginctl disable-linger deploy

loginctl show-user <user> -p Linger — Check if linger is enabled for a user.

loginctl show-user deploy -p Linger

Seats

loginctl list-seats — List all seats (physical workstations).

loginctl list-seats

loginctl seat-status <seat> — Show status of a seat.

loginctl seat-status seat0

loginctl 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

  • systemctl – control systemd services and units (including --user services)
  • journalctl – query the systemd journal and inspect session logs
  • su – switch users and run commands as another user