🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

loginctl Command

Intermediate Systemd & Services man(1)

Control the systemd login manager

👁 10 views 📅 Updated: Mar 15, 2026
SYNTAX
loginctl [COMMAND]

What Does loginctl Do?

loginctl manages user login sessions through systemd-logind. It shows active sessions, enables/disables user lingering, and controls seat and user management.

loginctl is useful for managing user sessions on multi-user servers, checking who is logged in, terminating sessions, and enabling services to run after user logout (linger).

User lingering (loginctl enable-linger) is particularly important for running user-level systemd services that need to persist after the user logs out.

Options & Flags

OptionDescriptionExample
list-sessions Show active sessions loginctl list-sessions
list-users Show logged-in users loginctl list-users
show-session Show session details loginctl show-session SESSION_ID
terminate-session End a session sudo loginctl terminate-session SESSION_ID
enable-linger Allow user services after logout sudo loginctl enable-linger username
disable-linger Disable user lingering sudo loginctl disable-linger username

Practical Examples

#1 List sessions

Shows all active user sessions.
$ loginctl list-sessions
Output: SESSION UID USER SEAT TTY\n 1 1000 admin pts/0

#2 List users

Shows all logged-in users.
$ loginctl list-users
Output: UID USER\n1000 admin

#3 Terminate session

Ends a specific user session.
$ sudo loginctl terminate-session 3

#4 Enable linger

Allows the deploy user to run services even when not logged in.
$ sudo loginctl enable-linger deploy

#5 Session details

Shows detailed information about a session.
$ loginctl show-session 1

Tips & Best Practices

Enable linger for user services: loginctl enable-linger user allows systemd user services to run after logout. Essential for background services running as non-root.
Session management: loginctl manages sessions at the systemd level. It is more powerful than killing processes manually.
terminate-session kills everything: Terminating a session kills ALL processes in that session. Save work first.

Frequently Asked Questions

How do I see who is logged in?
loginctl list-sessions shows all sessions. loginctl list-users shows unique users.
How do I kick a user off?
Find their session with list-sessions, then: sudo loginctl terminate-session SESSION_ID.
What is lingering?
Lingering allows a user to have systemd services running even when not logged in. Enable with: loginctl enable-linger user.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →