LinuxCommandLibrary

loginctl

Manage user logins and sessions

TLDR

Print all current sessions

$ loginctl
copy

Print all properties of a specific session
$ loginctl show-session [session_id] [[-a|--all]]
copy

Print all properties of a specific user
$ loginctl show-user [username]
copy

Print a specific property of a user
$ loginctl show-user [username] [[-p|--property]] [property_name]
copy

Execute a loginctl operation on a remote host
$ loginctl list-users [[-H|--host]] [hostname]
copy

Log a user out on all of their sessions
$ loginctl terminate-user [username]
copy

Display help
$ loginctl [[-h|--help]]
copy

SYNOPSIS

loginctl [OPTIONS...] COMMAND [ARGS...]

Common Commands:
loginctl list-sessions
loginctl show-session ID
loginctl terminate-session ID
loginctl lock-session ID
loginctl unlock-session ID
loginctl list-users
loginctl show-user USERNAME
loginctl terminate-user USERNAME
loginctl suspend
loginctl hibernate
loginctl poweroff
loginctl reboot

PARAMETERS

--no-pager
    Do not pipe output into a pager.

-H, --host=
    Operate on a remote host via SSH.

-M, --machine=
    Operate on a local container or VM.

-l, --full
    Show full entries, even if they don't fit on the screen.

-a, --all
    Show all properties, including those not typically shown.

--user
    Operate on the calling user's session, typically when run as a regular user.

--uid=
    Operate on a specific user ID.

--session=
    Specify a session by its ID.

--seat=
    Specify a seat by its ID.

--property=
    When used with show-session/user/etc., displays only the specified property.

--value
    When used with --property, shows only the value, not the property name.

--no-legend
    Do not print the column headers.

--json=
    Format output as JSON. Accepted values: 'pretty', 'short', 'full', 'compact'.

-h, --help
    Display a short help text and exit.

--version
    Show package version.

DESCRIPTION

loginctl is a command-line utility for controlling the systemd login manager, systemd-logind.service. It provides a unified interface for managing user logins, sessions, seats, and users on a Linux system.

Administrators and users can use loginctl to query the current state of logged-in users and their sessions, terminate specific sessions, lock/unlock the screen, or initiate system-wide actions like suspend, hibernate, or shutdown. It replaces older mechanisms for session tracking and offers a modern, D-Bus-based approach to integrate seamlessly with various desktop environments and display managers. Its functionality extends to managing multiple physical seats and virtual sessions, offering granular control over the system's login environment.

CAVEATS

loginctl relies on the systemd-logind.service being active and running. Many commands require root privileges or specific user permissions (e.g., membership in the systemd-journal group for certain logging operations or proper Polkit policies). Misuse of termination commands can lead to data loss if users are not properly warned or sessions are not saved.

COMMON USE CASES

Listing Sessions and Users:
To see all active login sessions: loginctl list-sessions
To see all logged-in users: loginctl list-users

Detailed Information:
To show detailed information about a specific session (e.g., 'c1'): loginctl show-session c1
To show details for a user (e.g., 'johndoe'): loginctl show-user johndoe

Session Control:
To lock a session (e.g., 'c1'): loginctl lock-session c1
To terminate a session: loginctl terminate-session c1

System Control:
To initiate system suspend: loginctl suspend
To initiate system hibernate: loginctl hibernate

HISTORY

loginctl was introduced as part of the systemd init system, first widely adopted in the early 2010s. It was designed to replace or integrate with existing login management components like ConsoleKit and PolicyKit, providing a more robust and unified D-Bus-based interface for session tracking and management. Its development aimed to streamline the handling of multiple user sessions, virtual terminals, and physical seats, aligning with systemd's broader goal of modernizing Linux system management.

SEE ALSO

Copied to clipboard