Linux之lastb命令

列出登入系统失败的用户相关信息。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/...
微信公众号:入门小站

  • 回复【1001】获取 linux常用命令速查手册
  • 回复【10010】获取 阿里云ECS运维Linux系统诊断
  • 回复【10012】获取 Linux学习笔记【强悍总结值得一看】
  • 回复【10013】获取 shell简明教程

你可能感兴趣的:(linux)