关于linux:Linux之lastb命令

10次阅读

共计 1609 个字符,预计需要花费 5 分钟才能阅读完成。

列出登入零碎失败的用户相干信息。lastb 命令 用于显示用户谬误的登录列表,此指令能够发现零碎的登录异样。独自执行 lastb 命令,它会读取位于 /var/log 目录下,名称为 btmp 的文件,并把该文件内容记录的登入失败的用户名单,全副显示进去。

命令语法

lastb [选项] [参数]

命令选项

  • -a:把从何处登入零碎的主机名称或 ip 地址显示在最初一行;
  • -d:将 IP 地址转换成主机名称;
  • -f< 记录文件 >:指定记录文件;
  • -n< 显示列数 > 或 -< 显示列数 >:设置列出名单的显示列数;
  • -R:不显示登入零碎的主机名称或 IP 地址;
  • -x:显示零碎关机,从新开机,以及执行等级的扭转等信息。

命令参数

  • 用户名:显示中的用户的登录列表;
  • 终端:显示从指定终端的登录列表。

应用 ssh 的登录失败不会记录在 btmp 文件中。

> lastb | head
root     ssh:notty    120.132.112.75   Sun Apr 11 22:18 - 22:18  (00:00)    
root     ssh:notty    185.36.81.44     Sun Apr 11 22:18 - 22:18  (00:00)    
root     ssh:notty    101.89.138.113   Sun Apr 11 22:18 - 22:18  (00:00)    
admin1   ssh:notty    123.21.35.183    Sun Apr 11 22:18 - 22:18  (00:00)    
admin1   ssh:notty    123.21.35.183    Sun Apr 11 22:17 - 22:17  (00:00)    
adria    ssh:notty    132.232.32.203   Sun Apr 11 22:17 - 22:17  (00:00)    
adria    ssh:notty    132.232.32.203   Sun Apr 11 22:17 - 22:17  (00:00)    
root     ssh:notty    115.79.35.110    Sun Apr 11 22:17 - 22:17  (00:00)    
user     ssh:notty    103.248.31.50    Sun Apr 11 22:17 - 22:17  (00:00)    
user     ssh:notty    103.248.31.50    Sun Apr 11 22:17 - 22:17  (00:00)

lastb 指令,它会读取位于 /var/log/btmp 的文件,并把该文件内容记录的登入零碎失败的用户名单,全副显示进去。btmp 是二进制文件,所以用 last -f /var/log/btmp 后果一样。

找出指定用户名登录失败的记录

> lastb root | head
root     ssh:notty    123.21.35.183    Sun Apr 11 22:25 - 22:25  (00:00)    
root     ssh:notty    123.21.35.183    Sun Apr 11 22:24 - 22:24  (00:00)    
root     ssh:notty    123.21.35.183    Sun Apr 11 22:24 - 22:24  (00:00)    
root     ssh:notty    120.132.112.75   Sun Apr 11 22:24 - 22:24  (00:00)    
root     ssh:notty    81.69.251.186    Sun Apr 11 22:23 - 22:23  (00:00)    
root     ssh:notty    123.21.35.183    Sun Apr 11 22:23 - 22:23  (00:00)    
root     ssh:notty    123.21.35.183    Sun Apr 11 22:22 - 22:22  (00:00)    
root     ssh:notty    81.69.251.186    Sun Apr 11 22:21 - 22:21  (00:00)    
root     ssh:notty    120.132.112.75   Sun Apr 11 22:21 - 22:21  (00:00)    
root     ssh:notty    120.132.112.75   Sun Apr 11 22:18 - 22:18  (00:00)

革除 lastb 对应的文件内容

> echo > /var/log/btmp

原文链接:https://rumenz.com/rumenbiji/…
微信公众号: 入门小站

正文完
 0