系統運維-用戶管理-查詢Linux用戶登陸記錄 介紹 查看當前登錄用戶 查看所有自 /var/log/wtmp 創立以來登錄過的用戶 查看7日內登錄的用戶

這裏給出Linux下查詢用戶登陸記錄的常用方法。

介紹

引用網址: https://www.cnblogs.com/applelife/p/10450353.html

有關用戶登錄的信息記錄在 utmp(/var/run/utmp)、wtmp(/var/log/wtmp)、btmp(/var/log/btmp) 和 lastlog(/var/log/lastlog) 等文件中。
who、w 和 users 等命令通過 utmp(/var/run/utmp) 文件查詢當前登錄用戶的信息。
last 和 ac 命令通過 wtmp(/var/log/wtmp) 文件查詢當前與過去登錄系統的用戶的信息。
lastb 命令通過 btmp(/var/log/btmp) 文件查詢所有登錄系統失敗的用戶的信息。
lastlog 命令通過 lastlog(/var/log/lastlog) 文件查詢用戶最後一次登錄的信息。

下面是一些命令的舉例。

查看當前登錄用戶

root@cnszs215:~/scm# w
 14:58:35 up 114 days, 20:06,  7 users,  load average: 0.37, 0.44, 0.42
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ian.chen pts/2    172.16.246.57    11:33    1:23m 37:35  22:41  rsync -avzP [email protected]:/home2/ian.chen/project/2k20_5599 .
miracle. pts/15   172.16.246.74:S. 06Dec19 78days  0.25s  0.25s /bin/bash
miracle. pts/16   172.16.246.74:S. 06Dec19 110days 13.97s  0.02s ssh -o ControlMaster no -o ControlPath /tmp/ssh-mdE24m/master-%r@%h:%p url git-upload-pack '/tpv/apollo/sys_build'
miracle. pts/21   172.16.246.74:S. 31Dec19  1.00s  1.93s  1.16s /bin/bash
miracle. pts/5    172.16.246.74:S. 02Jan20 56:17   0.78s  0.78s /bin/bash
miracle. pts/23   172.16.246.74:S. 02Jan20  1:17m  1.69s  1.69s /bin/bash
miracle. pts/22   172.16.246.74:S. 08Jan20 76days  0.82s  0.82s /bin/bash
root@cnszs215:~/scm#

查看所有自 /var/log/wtmp 創立以來登錄過的用戶

#last

查看7日內登錄的用戶

root@cnszs215:~/scm# lastlog -t 7
Username         Port     From             Latest
miracle.lv       pts/2    172.16.246.74    Wed Mar 25 16:20:45 +0800 2020
janq.liu         pts/2    172.16.246.43    Fri Mar 20 12:00:09 +0800 2020
ian.chen         pts/2    172.16.246.57    Thu Mar 26 11:33:30 +0800 2020
janq.liu         pts/2    172.16.246.43    Fri Mar 20 12:00:09 +0800 2020
miracle.lv       pts/2    172.16.246.74    Wed Mar 25 16:20:45 +0800 2020
ian.chen         pts/2    172.16.246.57    Thu Mar 26 11:33:30 +0800 2020

查看登錄失敗的記錄

root@cnszs215:~/scm# lastb 
fly.zhan ssh:notty    172.16.246.74    Wed Mar 11 15:12 - 15:12  (00:00)    
paul.den ssh:notty    172.16.246.74    Wed Mar 11 14:51 - 14:51  (00:00)    
paul.den ssh:notty    172.16.246.74    Wed Mar 11 14:51 - 14:51  (00:00)    
paul.den ssh:notty    172.16.246.74    Wed Mar 11 14:41 - 14:41  (00:00)    
fly.zhan ssh:notty    172.16.246.74    Wed Mar 11 14:39 - 14:39  (00:00)    
fly.zhan ssh:notty    172.16.246.74    Wed Mar 11 14:34 - 14:34  (00:00)    
fly.zhan ssh:notty    172.16.246.74    Wed Mar 11 14:34 - 14:34  (00:00)    
miracle  ssh:notty    172.16.246.74    Wed Mar 11 14:24 - 14:24  (00:00)    

btmp begins Wed Mar 11 14:24:10 2020
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章