System and processes

The loginctl command

Lists and controls the sessions and users managed by systemd-logind.

Syntax

loginctl [opciones] {orden} [nombre...]Try it in the terminal →

Most useful options

-a, --allAlso shows empty properties when querying sessions, users or seats
-p, --property= PROPIEDADLimits the output to that property, for example Sessions. It can be repeated
--valuePrints only the value of the property, without its name or the = sign
-n, --lines= NWith user-status and session-status, how many recent journal lines are shown. Defaults to 10
-H, --host= [usuario@]equipoRuns the command on another machine, connecting over SSH
--no-legendDoes not print column headers or the footer with hints
--no-pagerDoes not send the output to a pager

Copy-ready examples

$ loginctl list-sessionsopen sessions on this machine, with their user and seat.
$ loginctl user-status -n 5status of your user and the last five journal lines for it.
$ loginctl --value -p State show-user $USERonly your user's state, without labels, to use in a script.
$ sudo loginctl terminate-user usuarioCAREFUL: closes all sessions of that user and kills their processes. Use it only if you really need to disconnect that user.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
System has not been booted with systemd as init system (PID 1). Can't operate.The machine was not booted with systemd as PID 1, so there is no session manager to ask. It happens in containers and in environments without systemd.Run the command on a machine that uses systemd, or connect to one with -H.

Typical mistakes

  • With no argument, user-status and session-status look at your own user or your own session. For another account, give its name.
  • terminate-session and terminate-user kill processes right away: check the name or the ID before pressing Enter.
  • Session IDs are not fixed: they change with each login. In a script, get them with list-sessions instead of typing them by hand.

Differences from similar commands

  • who: only shows who is logged in. loginctl gives the detail of each session and can lock or terminate it.
  • w: shows logged-in users and what they run. loginctl focuses on the sessions managed by logind.
  • systemctl: manages services and units. loginctl only deals with sessions, users and seats.

Related commands

FAQ

What is the difference between a session and a user in loginctl?

The same user can have several sessions open at once, for example a graphical one and one over SSH. list-users and list-sessions show each level separately.

What is a seat?

A group of input and output devices, such as the keyboard, screen and mouse, that a graphical session uses. You list them with loginctl list-seats.

Can loginctl query another machine?

Yes, with -H user@host, which connects over SSH. You need prior SSH access and, for commands that change something, administrator rights.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course