xiaobaoqiu Blog

Think More, Code Less

系统当前用户

经常需要查看当前服务器哪些用户在登录,以及他们都在干什么.

下面总结一些命令,其中last应该是最常用的命令.

1.w

w - Show who is logged on and what they are doing.

主要字段:

LOGIN@: 什么时间登录的
PCPU: 当前进程所用时间
WHAT: 用户当前正在使用的命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
xiaobaoqiu@xiaobaoqiu:~/octopress$ w
 20:32:42 up  9:59, 15 users,  load average: 1.80, 1.26, 1.17
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
xiaobaoq tty7     :0               10:34    9:58m 22:26   0.48s init --user
xiaobaoq pts/1    :0               10:35    2:22m  0.12s  0.12s /bin/bash
xiaobaoq pts/2    :0               11:12   44:10   0.26s  0.19s ssh cn6
xiaobaoq pts/7    :0               11:12    9:02m  0.15s  0.09s ssh cn6
xiaobaoq pts/8    :0               11:28    5:56m  0.09s  0.03s ssh cn5
xiaobaoq pts/12   :0               13:09    3:03m  0.30s  0.24s ssh cn0
xiaobaoq pts/13   :0               13:09    3:14m  0.13s  0.07s mysql -h...
xiaobaoq pts/14   :0               13:09    3:00m  1.23s  1.17s ssh cn0
xiaobaoq pts/18   :0               13:09    3:03m  3.42s  3.35s ssh cn0
xiaobaoq pts/20   :0               13:14    3:01m  0.45s  0.39s mysql -h...
xiaobaoq pts/22   :0               13:26    7:01m  0.13s  0.07s ssh cn0
xiaobaoq pts/23   :0               14:02   40:34   0.17s  0.17s /bin/bash
xiaobaoq pts/24   :0               14:03    2.00s  0.23s  0.00s w
xiaobaoq pts/25   :0               14:36    2:02   0.24s  0.18s ssh cn5
xiaobaoq pts/26   :0               17:41    2:47m  0.09s  0.09s /bin/bash

2.who

who - show who is logged on

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
xiaobaoqiu@xiaobaoqiu:~/octopress$ who
xiaobaoqiu tty7         2015-07-15 10:34 (:0)
xiaobaoqiu pts/1        2015-07-15 10:35 (:0)
xiaobaoqiu pts/2        2015-07-15 11:12 (:0)
xiaobaoqiu pts/7        2015-07-15 11:12 (:0)
xiaobaoqiu pts/8        2015-07-15 11:28 (:0)
xiaobaoqiu pts/12       2015-07-15 13:09 (:0)
xiaobaoqiu pts/13       2015-07-15 13:09 (:0)
xiaobaoqiu pts/14       2015-07-15 13:09 (:0)
xiaobaoqiu pts/18       2015-07-15 13:09 (:0)
xiaobaoqiu pts/20       2015-07-15 13:14 (:0)
xiaobaoqiu pts/22       2015-07-15 13:26 (:0)
xiaobaoqiu pts/23       2015-07-15 14:02 (:0)
xiaobaoqiu pts/24       2015-07-15 14:03 (:0)
xiaobaoqiu pts/25       2015-07-15 14:36 (:0)
xiaobaoqiu pts/26       2015-07-15 17:41 (:0)

3.users

users - print the user names of users currently logged in to the current host

1
2
xiaobaoqiu@xiaobaoqiu:~/octopress$ users
xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu xiaobaoqiu

4.whoami

whoami - print effective userid

1
2
3
4
5
6
7
8
xiaobaoqiu@xiaobaoqiu:~/octopress$ whoami
xiaobaoqiu

xiaobaoqiu@xiaobaoqiu:~/octopress$ who am i
xiaobaoqiu pts/24       2015-07-15 14:03 (:0)

xiaobaoqiu@xiaobaoqiu:~/octopress$ who mom likes
xiaobaoqiu pts/24       2015-07-15 14:03 (:0)

5.id

id - print real and effective user and group IDs

1
2
xiaobaoqiu@xiaobaoqiu:~/octopress$ id
uid=1000(xiaobaoqiu) gid=1000(xiaobaoqiu) 组=1000(xiaobaoqiu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)

6.last

last, lastb - show listing of last logged in users

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
xiaobaoqiu@xiaobaoqiu:~/octopress$ last
xiaobaoq pts/26       :0               Wed Jul 15 17:41   still logged in   
xiaobaoq pts/25       :0               Wed Jul 15 14:36   still logged in   
xiaobaoq pts/24       :0               Wed Jul 15 14:03   still logged in   
xiaobaoq pts/23       :0               Wed Jul 15 14:02   still logged in   
xiaobaoq pts/22       :0               Wed Jul 15 13:26   still logged in   
xiaobaoq pts/20       :0               Wed Jul 15 13:14   still logged in   
xiaobaoq pts/20       :0               Wed Jul 15 13:14 - 13:14  (00:00)    
xiaobaoq pts/18       :0               Wed Jul 15 13:09   still logged in   
xiaobaoq pts/14       :0               Wed Jul 15 13:09   still logged in   
xiaobaoq pts/13       :0               Wed Jul 15 13:09   still logged in   
xiaobaoq pts/12       :0               Wed Jul 15 13:09   still logged in   
xiaobaoq pts/8        :0               Wed Jul 15 11:28   still logged in   
xiaobaoq pts/7        :0               Wed Jul 15 11:12   still logged in   
xiaobaoq pts/2        :0               Wed Jul 15 11:12   still logged in   
xiaobaoq pts/1        :0               Wed Jul 15 10:35   still logged in