
Linuxでログインしているユーザの一覧をloginctlコマンドで表示します。
記事の目次
loginctlコマンドのヘルプを表示する!
loginctlコマンドのヘルプを表示して使用方法を確認します。
$ loginctl --help
loginctl [OPTIONS...] COMMAND ...
Send control commands to or query the login manager.
Session Commands:
list-sessions List sessions
session-status [ID...] Show session status
show-session [ID...] Show properties of sessions or the manager
activate [ID] Activate a session
lock-session [ID...] Screen lock one or more sessions
unlock-session [ID...] Screen unlock one or more sessions
lock-sessions Screen lock all current sessions
unlock-sessions Screen unlock all current sessions
terminate-session ID... Terminate one or more sessions
kill-session ID... Send signal to processes of a session
User Commands:
list-users List users
user-status [USER...] Show user status
show-user [USER...] Show properties of users or the manager
enable-linger [USER...] Enable linger state of one or more users
disable-linger [USER...] Disable linger state of one or more users
terminate-user USER... Terminate all sessions of one or more users
kill-user USER... Send signal to processes of a user
Seat Commands:
list-seats List seats
seat-status [NAME...] Show seat status
show-seat [NAME...] Show properties of seats or the manager
attach NAME DEVICE... Attach one or more devices to a seat
flush-devices Flush all device associations
terminate-seat NAME... Terminate all sessions on one or more seats
Options:
-h --help Show this help
--version Show package version
--no-pager Do not pipe output into a pager
--no-legend Do not show the headers and footers
--no-ask-password Don't prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
-p --property=NAME Show only properties by this name
-P NAME Equivalent to --value --property=NAME
-a --all Show all properties, including empty ones
--value When showing properties, only print the value
-l --full Do not ellipsize output
--kill-who=WHO Who to send signal to
-s --signal=SIGNAL Which signal to send
-n --lines=INTEGER Number of journal entries to show
-o --output=STRING Change journal output mode (short, short-precise,
short-iso, short-iso-precise, short-full,
short-monotonic, short-unix, verbose, export,
json, json-pretty, json-sse, json-seq, cat,
with-unit)
See the loginctl(1) man page for details.
ログイン中のセッションの一覧を表示する!
セッションの観点でログインしているユーザの一覧を表示する!
$ loginctl
SESSION UID USER SEAT TTY
2 1000 usradmin pts/0
5 1000 usradmin pts/1
c1 42 gdm seat0 tty1
$ loginctl list-sessions
SESSION UID USER SEAT TTY
2 1000 usradmin pts/0
5 1000 usradmin pts/1
c1 42 gdm seat0 tty1
3 sessions listed.
[usradmin@vmsans01 ~]$ who
usradmin pts/0 2023-01-11 20:03 (10.1.1.1)
usradmin pts/1 2023-01-12 21:09 (10.1.1.1)
従来のwhoコマンドにあたる内容が表示されますが、ログイン元のIPアドレスの情報は表示されません。
ログイン中のユーザの一覧を表示する!
ログイン中のユーザをユーザ名のみの一覧で表示します。
$ loginctl list-users UID USER 42 gdm 1000 usradmin 2 users listed. $ users usradmin usradmin
従来のusersコマンドにあたる内容が表示されます。
ログインおよびOS再起動の履歴を確認する!(last)
ログインおよびOS再起動の履歴は、loginctlでは表示できず、lastコマンドを使用します。
$ last usradmin pts/1 10.1.1.1 Thu Jan 12 21:09 still logged in usradmin pts/1 10.1.1.1 Thu Jan 12 20:46 - 21:09 (00:22) usradmin pts/0 10.1.1.1 Wed Jan 11 20:03 - 21:29 (1+01:25) reboot system boot 5.14.0-162.6.1.e Wed Jan 11 20:03 still running usradmin pts/0 10.1.1.1 Tue Jan 10 22:00 - crash (22:03) reboot system boot 5.14.0-162.6.1.e Tue Jan 10 21:19 still running usradmin pts/1 10.1.1.1 Sun Jan 8 17:30 - 17:30 (00:00) ...
おわりに
ログインしているユーザの一覧は、loginctlコマンドを使用すると、見やすい一覧で表示されますが、ログイン元にIPアドレスが表示できないのが残念なところです。
関連記事
関連書籍(Amazon)

