您的位置:首页 > 运维架构 > Linux

【Linux学习笔记】16:用户登录查看命令

2017-08-26 00:08 786 查看

[1]w和who查看用户登录信息

[root@bogon cdrom]# w
07:47:24 up  6:26,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.0.104    04:50    0.00s  0.28s  0.00s w


TTY表示用户登录终端(tty1表示本机登录,pts/0表示第一个远程工具),IDLE表示闲置时间,JCPU和PCPU越大,表示这个用户占用的CPU资源越大。

在虚拟机本机上登录,再来查看一下:

[root@bogon ~]# w
07:51:35 up  6:30,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     -                07:51   19.00s  0.04s  0.04s -bash
root     pts/0    192.168.0.104    04:50    0.00s  0.37s  0.07s w


用who命令也可以查看用户登录信息,但是信息较少:

[root@bogon ~]# who
root     tty1         2017-08-26 07:51
root     pts/0        2017-08-26 04:50 (192.168.0.104)


[2]last和lastlog查看过去登录的用户信息

[root@bogon ~]# last
root     tty1                          Sat Aug 26 07:51   still logged in
root     pts/0        192.168.0.104    Sat Aug 26 04:50   still logged in
root     pts/0        192.168.0.104    Sat Aug 26 01:22 - 04:45  (03:23)
reboot   system boot  2.6.32-358.el6.x Sat Aug 26 01:20 - 07:55  (06:34)
root     pts/0        192.168.0.104    Fri Aug 25 19:09 - down   (01:31)
reboot   system boot  2.6.32-358.el6.x Fri Aug 25 19:08 - 20:41  (01:32)
root     pts/0        192.168.0.103    Fri Aug 25 01:44 - down   (06:51)
reboot   system boot  2.6.32-358.el6.x Fri Aug 25 01:39 - 08:35  (06:55)
root     pts/1        192.168.0.103    Thu Aug 24 05:59 - down   (03:18)
root     pts/0        192.168.0.103    Thu Aug 24 03:36 - 08:09  (04:32)
reboot   system boot  2.6.32-358.el6.x Thu Aug 24 03:36 - 09:17  (05:41)
root     pts/0        192.168.0.103    Thu Aug 24 03:26 - down   (00:09)
root     tty1                          Thu Aug 24 03:24 - down   (00:11)
reboot   system boot  2.6.32-358.el6.x Thu Aug 24 03:19 - 03:35  (00:16)
root     pts/0        192.168.0.103    Wed Aug 23 06:21 - 06:22  (00:00)
root     tty1                          Wed Aug 23 06:17 - crash  (21:01)
reboot   system boot  2.6.32-358.el6.x Wed Aug 23 06:16 - 03:35  (21:19)
root     tty1                          Wed Aug 23 06:07 - crash  (00:08)
reboot   system boot  2.6.32-358.el6.x Wed Aug 23 06:06 - 03:35  (21:28)
root     pts/0        192.168.0.103    Wed Aug 23 04:27 - 04:29  (00:02)
root     tty1                          Tue Aug 22 18:24 - down   (10:07)
reboot   system boot  2.6.32-358.el6.x Tue Aug 22 18:23 - 04:31  (10:08)

wtmp begins Tue Aug 22 18:23:19 2017


last命令默认是读取/var/log/wtmp文件的数据,尝试用vi阅读它:



可以看到它是一个加密了的,防止人为地去修改它。

lastlog查看所有用户的最后一次登录时间:

[root@bogon ~]# lastlog
用户名           端口     来自             最后登陆时间
root             tty1                      六 8月 26 07:51:17 +0800 2017
bin                                        **从未登录过**
daemon                                     **从未登录过**
adm                                        **从未登录过**
lp                                         **从未登录过**
sync                                       **从未登录过**
shutdown                                   **从未登录过**
halt                                       **从未登录过**
mail                                       **从未登录过**
uucp                                       **从未登录过**
operator                                   **从未登录过**
games                                      **从未登录过**
gopher                                     **从未登录过**
ftp                                        **从未登录过**
nobody                                     **从未登录过**
dbus                                       **从未登录过**
vcsa                                       **从未登录过**
rpc                                        **从未登录过**
abrt                                       **从未登录过**
rpcuser                                    **从未登录过**
nfsnobody                                  **从未登录过**
haldaemon                                  **从未登录过**
ntp                                        **从未登录过**
saslauth                                   **从未登录过**
postfix                                    **从未登录过**
sshd                                       **从未登录过**
tcpdump                                    **从未登录过**
oprofile                                   **从未登录过**


它默认读取/var/log/lastlog文件内容,它也不能直接用vi阅读:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: