コマンドラインからサーバーにログインしているユーザーを見つけることはできますか?はい、いくつかの Linux コマンドを使用して可能です。 Linux サーバーにログインしているユーザー名を検出する方法を見てみましょう。
サーバーにログインしているユーザーを見つけるための 3 つのコマンド
w コマンド
w コマンドは、サーバー内にログインしているユーザー数と実行中のプロセスに関する有用な情報を出力します。例:
[[email protected]:~]w 21:36:01 up 274 days, 17:33, 1 user, load average: 0.19, 0.24, 0.29 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT ultrauser pts/0 111.111.111.111 20:46 0.00s 0.02s 0.00s sshd: ultrauser [priv] [[email protected]:~]
特定のユーザーに関する詳細情報を表示するには、次のコマンドを実行できます:
w user
user はユーザー名です。例:
[[email protected] ~]$ w webtech 23:39:16 up 54 min, 1 user, load average: 0,48, 0,48, 0,41 USER TTY [email protected] IDLE JCPU PCPU WHAT webtech tty2 22:45 54:28 14:38 2.52s /opt/google/chrome/chrome --type=renderer --enable-features=*AutofillCreditCardSigninPromo<AutofillCr [[email protected] ~]$
指揮者
who コマンドは、サーバーにログインしているユーザーを見つけるのに役立つ別のコマンドです。
出力例:
[[email protected]:~]who ultrauser pts/0 2017-01-29 20:46 (111.111.111.111) [[email protected]:~]
-a オプションを使用して、すべての完全な情報を出力することもできます。出力例:
[[email protected]:~]who -a system boot 2016-04-30 05:03 run-level 3 2016-04-30 05:03 LOGIN tty1 2016-04-30 05:03 7200 id=1 LOGIN tty2 2016-04-30 05:03 7202 id=2 LOGIN tty3 2016-04-30 05:03 7204 id=3 LOGIN tty4 2016-04-30 05:03 7206 id=4 LOGIN tty5 2016-04-30 05:03 7208 id=5 LOGIN tty6 2016-04-30 05:03 7210 id=6 ultrauser + pts/0 2017-01-29 20:46 . 13648 (111.111.111.111) pts/1 2017-01-27 08:45 24158 id=ts/1 term=0 exit=0 pts/2 2016-09-16 15:08 32364 id=ts/2 term=0 exit=0 pts/3 2017-01-04 17:09 15024 id=ts/3 term=0 exit=0 pts/2 2016-07-22 08:45 22855 id=/2 term=0 exit=0 pts/1 2016-10-03 16:41 25856 id=/1 term=0 exit=0 pts/4 2017-01-03 16:52 25470 id=ts/4 term=0 exit=0 pts/5 2017-01-03 13:31 26228 id=ts/5 term=0 exit=0 [[email protected]:~]
who コマンドに渡すオプションは多数あります:
-a, --all same as -b -d --login -p -r -t -T -u -b, --boot time of last system boot -d, --dead print dead processes -H, --heading print line of column headings -l, --login print system login processes --lookup attempt to canonicalize hostnames via DNS -m only hostname and user associated with stdin -p, --process print active processes spawned by init -q, --count all login names and number of users logged on -r, --runlevel print current runlevel -s, --short print only name, line, and time (default) -t, --time print last system clock change -T, -w, --mesg add user's message status as +, - or ? -u, --users list users logged in --message same as -T --writable same as -T --help display this help and exit --version output version information and exit
ユーザー コマンド
users コマンドは、現在システムにログインしているユーザーのログイン名を出力しますが、順序付けされ、1 行で表示されます。 users コマンドは、utmp ファイルから情報を読み取ります。
出力例:
[[email protected]:~]users ultrauser johndoe linuxuser2 alterego34
ご覧のとおり、「users」コマンドは非常に基本的なものであり、あまり多くの情報を取得することはできません.
フィンガーコマンド
finger コマンドは、サーバーにログインしているユーザーを見つけるためのコマンドではありませんが、詳細を知る必要がある場合にユーザー情報を取得するのに役立ちます。
出力例:
[[email protected]:~]finger ultrauser Login: ultrauser Name: John Bonachon Directory: /home/ultrauser Shell: /bin/bash On since Sun Jan 29 20:46 (EST) on pts/0 from 111.111.111.111 No mail. No Plan.
ご覧のとおり、finger コマンドを使用すると、使用されているシェルの種類、ホーム ディレクトリ、本名、ログイン ユーザー名、最後にオンラインで表示された時刻などの詳細情報を見つけることができます。
参照:
- コマンドを実行する Linux
- Linux w コマンド