Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

loginctl

Show and control user logins (sessions), users and seats of systemd-logind — and turn on "linger" so a user's services run without a login.

Niveau
Dagelijks Linux
Groep
Gebruikers en groepen
Root nodig
Voor wijzigingen
Pakket
systemd

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Every login (console, SSH, desktop) is a session. loginctl lists sessions and users, shows their processes, locks or ends them, and controls linger: with linger on, systemd starts the user's own service manager at boot and keeps it running after logout. Rootless Podman containers and user timers need linger to run when the user is not logged in.

Zo schrijf je het

loginctl [OPTION]... COMMAND [NAME]...

Belangrijkste delen

Sessions

list-sessions
List the current sessions.
session-status [ID]...
Status and processes of a session.
show-session [ID]...
Properties of a session (for scripts).
activate [ID]
Bring a session to the front.
lock-session / unlock-session [ID]...
Lock or unlock the screen of a session.
lock-sessions / unlock-sessions
Lock or unlock all sessions.
terminate-session ID...
End a session (all its processes).
kill-session ID...
Send a signal to the processes of a session.

Users

list-users
List logged-in users (and users with linger).
user-status [USER]...
Status and processes of a user.
show-user [USER]...
Properties of a user (Linger=, State=).
enable-linger [USER]...
Keep the user's service manager running without a login.
disable-linger [USER]...
Turn linger off.
terminate-user USER...
End all sessions of a user.
kill-user USER...
Send a signal to all processes of a user.

Seats

list-seats / seat-status / show-seat
Seats (a screen, keyboard and mouse set).
attach NAME DEVICE...
Give a device to a seat.
flush-devices
Remove all device-to-seat assignments.
terminate-seat NAME...
End all sessions on a seat.

Opties 13

Meest gebruikt

Options

-p, --property=NAME
Show only this property (with show-*).
--value
Print only the value (with -p).
-a, --all
Show also empty properties.
-l, --full
Do not cut long lines.
--kill-whom=leader|all
With kill-*: the leader process or all processes.
-s, --signal=SIGNAL
The signal for kill-* (default SIGTERM).
-n, --lines=N
Journal lines in *-status.
-o, --output=MODE
Format of those journal lines.
-H, --host=HOST
Run on a remote host over SSH.
-M, --machine=NAME
Run in a container.
--no-ask-password
Do not ask for a password (polkit).
--no-pager / --no-legend
Plain output for scripts.
-h, --help / --version
Help / version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Who is logged in?

    loginctl list-sessions
    SESSION  UID USER    SEAT  TTY   STATE  IDLE SINCE
          3 1000 student seat0 tty2  active no   -
         12 1001 anna    -     pts/1 active no   -
    loginctl list-users
  2. 2Look at one session and its processes

    loginctl session-status 12
  3. 3End the session of a user

    loginctl terminate-session 12
    loginctl terminate-user anna

    Ends all logins and processes of anna. Tell the user first.

  4. 4Let a user's containers and timers run without a login

    loginctl enable-linger student
    loginctl show-user student -p Linger --value
    yes
    ls /var/lib/systemd/linger/
    student
  5. 5Turn linger off again

    loginctl disable-linger student
  6. 6Lock all screens (for example before a desktop maintenance)

    loginctl lock-sessions
  7. 7Kill only the processes of a user with a signal

    loginctl kill-user omar --signal=SIGKILL
  8. 8Use a property in a script

    loginctl show-session $XDG_SESSION_ID -p Type --value
    wayland
  9. 9Check if a user's service manager runs

    loginctl user-status student | head -5
    systemctl status user@1000.service
  10. 10Show the idle time of every session

    loginctl list-sessions --no-legend | while read id uid user rest; do echo "$user $(loginctl show-session $id -p IdleHint --value)"; done

Let op

  • Without linger, user services (Quadlet containers, user timers) stop at logout and do not start at boot.
  • terminate-user ends all processes of the user, also running jobs.

Bestanden

/var/lib/systemd/linger/
One file per user with linger on.
/etc/systemd/logind.conf, /etc/systemd/logind.conf.d/
Settings of systemd-logind (idle actions, KillUserProcesses).

Tips om te onthouden

  • loginctl enable-linger without a name works for your own user if polkit allows it.

Exitcodes

0Success.
Not 0Error.