如何获取活动登录会话的列表?


16

11月9日17:55:46 swi007 systemd-logind [927]:用户swi007的新会话27。

我想查看ubuntu服务器中活动登录会话的列表,并想关闭服务器中的特定会话。

Answers:


29

以下是获取当前会话列表的几种方法:

  • 命令who-显示谁在系统上:

    $ who
    spas     pts/1        2017-11-05 21:43 (tmux(1597).%0)
    spas     pts/14       2017-11-09 13:02 (192.168.100.110)
    guest    tty2         2017-11-09 16:15 (:1)
  • 命令w-显示有关计算机上当前用户的信息:

    $ w
     16:16:12 up 3 days, 18:33,  9 users,  load average: 4,33, 2,79, 2,44
    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
    spas     pts/1    tmux(1597).%0    нд21    3days  3days  3days tmux new-session -d -s my-tmux-session
    spas     pts/14   192.168.100.110  13:02    1.00s  0.29s  0.01s sshd: spas [priv]
    guest    tty2     :1               16:15    3days  1.27s  0.17s /sbin/upstart --user
  • 命令last lastb-显示最近登录用户的(历史)列表。它提供了一些分析选项--until--since等等。

  • 命令users-打印当前登录到当前主机的用户的用户名。它的用法确实很有限:

    $ users
    guest spas spas

要终止特定的会话,您可以使用who -u(或who -a)打印进程号,然后sudo kill -9 <session-process-number>

$ who -u
spas     pts/1        2017-11-05 21:43  old         1597 (tmux(1597).%0)
spas     pts/14       2017-11-09 13:02   .         31822 (192.168.100.110)
guest    tty2         2017-11-09 16:15  old         2225 (:1)

$ sudo kill -9 2225   # this command will kill the third session from the above list

另外,您可以杀死特定用户的所有进程(参考):

sudo pkill -9 -u <username>

也可以看看:


如何
取消

@zapoxkrishna,检查更新。
pa4080

您错过了last列出所有活动会话的命令:)
Videonauth

谢谢@Videonauth!确实,我从未使用过此命令。我已经更新了答案。
pa4080
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.