在工作中,我们有时候会经常的切换用户,有时候会忘记切换到哪个用户了,我们就需要知道当前登录的用户时谁,可以使用:
whoami
查看当前登录到系统中的用户有哪些:
who
列表中显示,第一列是用户名,第二列是连接的终端,tty 表示显示器,pts 表示远程连接;第三列是登录的时间;
若只是要查看当前有哪些用户在线:
users
其实查出来的跟who查出来的用户时一模一样的,只是这里比较简洁,只有当前登录的用户名而已;
那些登录到系统里的人都在干什么?
现在我们知道登录的用户有哪些了,那他们究竟在干什么呢,我们可以进一步的调查他们。可以通过w命令,w命令用于显示已经登录系统的用户的名称,以及他们正在做的事。该命令所使用的信息来源于/var/run/utmp文件。
第一行与uptime命令查出来的一样,依次表示:当前时间、系统运行时间、当前系统用户数量、平均负载;
从第二行开始构成一个表格,共有8个栏目,分别显示各个用户正在做的事情及该用户所占用的系统资源;
USER:显示登陆用户帐号名。用户重复登陆,该帐号也会重复出现。
TTY:用户登陆所用的终端。
FROM:显示用户在何处登陆系统。
LOGIN@:是LOGIN AT的意思,表示登陆进入系统的时间。
IDLE:用户空闲时间,从用户上一次任务结束后,开始记时。
JCPU:一终端代号来区分,表示在某段时间内,所有与该终端相关的进程任务所耗费的CPU时间。
PCPU:指WHAT域的任务执行后耗费的CPU时间。
WHAT:表示当前执行的任务
如果说我们只想查看某个用户当前的行为,我们可以直接在 w
后跟上该用户名:
last命令:
可用于显示特定用户登录系统的历史记录。如果没有指定任何参数,则显示所有用户的历史信息。在默认情况下,这些信息(所显示的信息)将来源于/var/log/wtmp文件。该命令的输出结果包含以下几列信息:
用户名称;
tty设备号;
历史登录时间日期;
登出时间日期;
总工作时间;
CMREAD-SV43 /home/iufs> last iufs
iufs pts/8 10.73.158.228 Tue Dec 18 17:20 still logged in
iufs pts/6 10.73.158.228 Tue Dec 18 15:41 still logged in
iufs pts/7 10.73.158.228 Tue Dec 18 13:22 still logged in
iufs pts/6 10.73.158.228 Tue Dec 18 13:22 - 15:10 (01:48)
iufs pts/9 10.73.158.228 Tue Dec 18 11:15 - 11:40 (00:24)
iufs pts/8 10.73.158.228 Tue Dec 18 09:24 - 11:40 (02:15)
iufs pts/7 10.73.158.228 Tue Dec 18 09:21 - 11:40 (02:19)
iufs pts/6 10.73.158.228 Tue Dec 18 09:20 - 11:40 (02:20)
iufs pts/11 10.73.158.211 Mon Dec 17 17:26 - 19:34 (02:07)
iufs pts/7 10.73.158.211 Mon Dec 17 17:18 - 19:34 (02:15)
iufs pts/7 10.73.158.211 Mon Dec 17 17:14 - 17:18 (00:04)
iufs pts/12 10.73.158.242 Mon Dec 17 16:24 - 18:14 (01:49)
iufs pts/11 10.73.158.211 Mon Dec 17 15:17 - 17:12 (01:55)
iufs pts/7 10.73.158.211 Mon Dec 17 14:01 - 16:30 (02:28)
iufs pts/10 10.73.158.228 Mon Dec 17 10:51 - 21:00 (10:08)
iufs pts/9 10.73.158.228 Mon Dec 17 10:31 - 21:00 (10:29)
iufs pts/8 10.73.158.228 Mon Dec 17 10:31 - 21:00 (10:29)
iufs pts/7 10.73.158.211 Mon Dec 17 09:56 - 12:58 (03:01)
iufs pts/6 10.73.158.228 Mon Dec 17 09:50 - 21:00 (11:09)
iufs pts/7 10.73.158.228 Fri Dec 14 15:18 - 19:25 (04:07)
iufs pts/6 10.73.158.242 Fri Dec 14 14:41 - 18:05 (03:24)
iufs pts/8 10.73.158.228 Fri Dec 14 14:39 - 19:25 (04:45)
iufs pts/7 10.73.158.211 Fri Dec 14 14:38 - 14:39 (00:01)
iufs pts/6 10.73.158.242 Fri Dec 14 14:09 - 14:41 (00:31)
iufs pts/6 10.73.158.228 Fri Dec 14 10:00 - 11:37 (01:37)
iufs pts/6 10.73.158.228 Thu Dec 13 17:39 - 18:04 (00:24)
iufs pts/6 10.73.158.228 Thu Dec 13 14:21 - 14:23 (00:01)
iufs pts/6 10.73.158.228 Thu Dec 13 09:43 - 14:13 (04:29)
iufs pts/8 10.73.158.228 Wed Dec 12 19:51 - 19:54 (00:03)
iufs pts/8 10.73.158.242 Wed Dec 12 19:00 - 19:03 (00:03)
iufs pts/7 10.73.158.228 Wed Dec 12 18:53 - 19:54 (01:01)
iufs pts/7 10.73.158.242 Wed Dec 12 18:23 - 18:52 (00:28)
iufs pts/7 10.73.158.242 Wed Dec 12 18:21 - 18:22 (00:00)
iufs pts/6 10.73.158.228 Wed Dec 12 11:10 - 20:45 (09:35)
iufs pts/7 10.73.158.209 Tue Dec 11 17:23 - 17:59 (00:36)
iufs pts/7 10.73.158.209 Tue Dec 11 16:42 - 16:56 (00:13)
iufs pts/6 10.73.158.228 Tue Dec 11 15:10 - 21:00 (05:49)
iufs pts/5 10.73.158.228 Mon Dec 10 16:39 - 19:50 (03:11)
iufs pts/5 10.73.158.209 Mon Dec 10 15:03 - 15:09 (00:05)
iufs pts/5 10.73.158.209 Mon Dec 10 11:42 - 13:12 (01:30)
iufs pts/5 10.73.158.209 Fri Dec 7 14:06 - 17:21 (03:15)
iufs pts/5 10.73.158.209 Fri Dec 7 11:45 - 13:13 (01:28)
iufs pts/5 10.73.158.209 Thu Dec 6 17:50 - 18:01 (00:10)
iufs pts/5 10.73.158.209 Wed Dec 5 18:07 - 19:14 (01:07)
iufs pts/5 10.73.158.155 Wed Dec 5 15:25 - 15:49 (00:24)
iufs pts/5 10.73.158.209 Tue Dec 4 16:15 - 18:28 (02:13)
iufs pts/5 10.73.158.155 Mon Dec 3 14:45 - 19:03 (04:18)
iufs pts/5 10.73.158.209 Mon Dec 3 11:34 - 12:00 (00:25)
iufs pts/5 10.73.158.209 Fri Nov 30 11:05 - 13:18 (02:13)
iufs pts/5 10.73.158.209 Thu Nov 29 17:03 - 18:00 (00:56)
iufs pts/6 10.73.158.155 Thu Nov 29 16:48 - 18:13 (01:24)
iufs pts/5 10.73.158.209 Thu Nov 29 14:09 - 17:03 (02:53)
iufs pts/6 10.73.158.155 Thu Nov 29 11:40 - 13:10 (01:29)
iufs pts/5 10.73.158.209 Thu Nov 29 09:49 - 13:31 (03:41)
iufs pts/6 10.73.158.209 Wed Nov 28 18:12 - 18:15 (00:02)
iufs pts/6 10.73.158.209 Wed Nov 28 16:10 - 18:09 (01:58)
iufs pts/6 10.73.158.155 Wed Nov 28 10:53 - 12:36 (01:43)
iufs pts/5 10.73.158.228 Wed Nov 28 09:53 - 20:44 (10:50)
iufs pts/7 10.73.158.155 Tue Nov 27 11:42 - 13:28 (01:46)
iufs pts/6 10.73.158.157 Tue Nov 27 11:41 - 19:57 (08:16)
iufs pts/5 10.73.158.157 Tue Nov 27 11:41 - 19:57 (08:16)
iufs pts/5 10.73.158.228 Mon Nov 26 09:17 - 19:31 (10:13)
iufs pts/5 10.73.158.228 Fri Nov 23 14:54 - 19:49 (04:54)
iufs pts/5 10.73.158.228 Thu Nov 22 16:09 - 20:39 (04:30)
iufs pts/5 10.73.158.221 Wed Nov 21 10:51 - 20:00 (09:08)
iufs pts/5 10.73.158.209 Thu Nov 15 17:49 - 17:57 (00:08)
iufs pts/5 10.73.158.209 Thu Nov 15 14:41 - 17:42 (03:00)
iufs pts/5 10.73.158.209 Tue Nov 13 11:52 - 13:28 (01:36)
iufs pts/6 10.73.158.157 Tue Nov 13 09:29 - 15:53 (06:24)
iufs pts/5 10.73.158.209 Tue Nov 13 09:16 - 09:41 (00:24)
iufs pts/5 10.73.158.209 Mon Nov 12 16:28 - 16:47 (00:19)
iufs pts/5 10.73.158.209 Mon Nov 12 16:22 - 16:22 (00:00)
iufs pts/6 10.73.158.157 Mon Nov 12 14:22 - 19:42 (05:20)
iufs pts/5 10.73.158.209 Mon Nov 12 14:20 - 14:47 (00:26)
iufs pts/5 10.73.158.209 Mon Nov 12 09:35 - 11:30 (01:55)
iufs pts/5 10.73.158.157 Fri Nov 9 16:17 - 00:31 (08:13)
iufs pts/0 10.73.158.157 Fri Nov 9 16:17 - 00:31 (08:14)
iufs pts/5 10.73.158.209 Thu Nov 8 19:03 - 19:05 (00:01)
iufs pts/5 10.73.158.209 Thu Nov 8 17:11 - 18:31 (01:20)
iufs pts/0 10.73.158.157 Thu Nov 8 14:58 - 11:30 (20:31)
iufs pts/0 10.73.158.155 Thu Nov 8 10:51 - 12:41 (01:49)
iufs pts/0 10.73.158.155 Thu Nov 8 09:55 - 10:04 (00:09)
iufs pts/0 10.73.158.155 Wed Nov 7 17:03 - 18:55 (01:51)
iufs pts/0 10.73.158.209 Tue Nov 6 14:08 - 22:13 (08:04)
iufs pts/0 10.73.158.209 Tue Nov 6 11:16 - 13:19 (02:02)
iufs pts/6 10.73.158.209 Fri Nov 2 18:14 - 18:30 (00:16)
iufs pts/6 10.73.158.209 Fri Nov 2 17:53 - 18:10 (00:16)
iufs pts/5 10.212.142.99 Fri Nov 2 17:27 - 20:18 (02:50)
iufs pts/0 10.73.158.215 Fri Nov 2 17:17 - 18:29 (01:11)
iufs pts/5 10.73.158.215 Fri Nov 2 10:15 - 15:41 (05:26)
iufs pts/0 10.73.158.209 Fri Nov 2 10:12 - 13:19 (03:06)
iufs pts/0 10.73.158.215 Thu Nov 1 18:37 - 19:22 (00:45)
iufs pts/5 10.73.158.209 Thu Nov 1 18:35 - 19:09 (00:34)
iufs pts/5 10.73.158.209 Thu Nov 1 17:18 - 17:18 (00:00)
iufs pts/0 10.73.158.215 Thu Nov 1 16:40 - 18:36 (01:55)
iufs pts/0 10.73.158.209 Wed Oct 31 09:04 - 12:07 (03:02)
iufs pts/5 10.73.158.209 Mon Oct 29 18:29 - 19:52 (01:23)
iufs pts/0 10.73.158.215 Mon Oct 29 15:50 - 19:10 (03:20)
iufs pts/5 10.73.158.209 Mon Oct 29 10:54 - 12:57 (02:03)
iufs pts/0 10.73.158.228 Mon Oct 29 09:27 - 15:08 (05:40)
iufs pts/0 10.73.158.228 Fri Oct 26 16:58 - 19:00 (02:01)
iufs pts/0 10.73.158.209 Thu Oct 25 15:14 - 15:49 (00:35)
iufs pts/5 10.73.158.211 Wed Oct 24 22:00 - 22:00 (00:00)
iufs pts/0 10.212.142.212 Wed Oct 24 17:16 - 09:26 (16:10)
iufs pts/0 10.73.158.211 Wed Oct 24 16:32 - 16:40 (00:07)
iufs pts/0 10.73.158.228 Fri Oct 19 09:25 - 10:02 (00:37)
iufs pts/6 10.73.158.211 Wed Oct 17 16:14 - 17:33 (01:18)
iufs pts/5 10.73.158.217 Wed Oct 17 16:12 - 18:55 (02:43)
iufs pts/0 10.73.158.228 Wed Oct 17 13:06 - 19:44 (06:37)
iufs pts/5 10.73.158.211 Tue Oct 16 19:11 - 20:37 (01:26)
iufs pts/5 10.73.158.211 Tue Oct 16 17:03 - 18:08 (01:05)
iufs pts/0 10.73.158.228 Tue Oct 16 17:02 - 12:40 (19:37)
iufs pts/5 10.73.158.211 Tue Oct 16 09:12 - 10:07 (00:55)
iufs pts/0 10.73.158.217 Tue Oct 16 09:03 - 10:25 (01:22)
iufs pts/0 10.73.158.211 Mon Oct 15 19:43 - 20:29 (00:46)
iufs pts/0 10.73.158.228 Mon Oct 15 18:43 - 18:54 (00:11)
iufs pts/0 10.73.158.211 Mon Oct 15 14:52 - 15:33 (00:40)
iufs pts/6 10.73.158.211 Mon Oct 15 14:07 - 14:45 (00:38)
iufs pts/5 10.73.158.217 Mon Oct 15 09:27 - 09:02 (23:35)
iufs pts/0 10.73.158.228 Mon Oct 15 09:19 - 14:17 (04:58)
iufs pts/6 10.73.158.219 Fri Oct 12 17:12 - 18:30 (01:18)
iufs pts/0 10.73.158.228 Fri Oct 12 10:30 - 19:10 (08:40)
iufs pts/0 10.73.158.211 Thu Oct 11 21:45 - 22:08 (00:23)
iufs pts/0 10.73.158.211 Thu Oct 11 20:28 - 20:48 (00:19)
iufs pts/0 10.73.158.211 Thu Oct 11 18:49 - 20:24 (01:35)
iufs pts/0 10.73.158.211 Thu Oct 11 18:19 - 18:22 (00:02)
iufs pts/0 10.73.158.211 Thu Oct 11 17:56 - 18:09 (00:13)
iufs pts/0 10.73.158.211 Thu Oct 11 15:48 - 17:43 (01:55)
iufs pts/4 10.73.158.228 Thu Oct 11 15:31 - 20:10 (04:39)
iufs pts/0 10.73.158.211 Thu Oct 11 15:14 - 15:33 (00:19)
pkill -u
命令:
通过以上几个命令,我们可以大概知道某些用户的行为。如果我们想要踢除使坏的人员,那么就可以使用,但这个命令相当危险,有可能导致系统重启,所以不推荐使用这个命令。比较安全的做法是使用pkill
命令;
[alvin@VM_0_16_centos ~]$ sudo pkill -kill -t pts/3
#harry用户已经被踢除了
[alvin@VM_0_16_centos ~]$ w
17:04:37 up 29 days, 6:44, 5 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
alvin pts/0 116.199.102.65 07:25 5.00s 0.12s 0.00s w
root pts/1 116.199.102.65 11:05 5:59m 0.02s 0.02s -bash
alvin pts/2 116.199.102.65 11:05 5:59m 0.04s 0.05s sshd: alvin [priv]
kate pts/4 116.199.102.65 11:08 5:12m 11.94s 11.91s top
alvin pts/5 116.199.102.65 11:53 5:10m 0.02s 0.02s -bash