الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

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.

المستوى
لينكس اليومي
المجموعة
المستخدمون والمجموعات
يحتاج root
للتغييرات
الحزمة
systemd

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الأجزاء الرئيسية

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.

الخيارات 13

الأكثر استخدامًا

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.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع 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

انتبه

  • 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.

الملفات

/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).

نصائح للحفظ

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

رموز الخروج

0Success.
Not 0Error.