17370845950

linux显示失败登录记录是什么-lastb命令使用与实例

Linux lastb命令说明

在 Linux 系统中,lastb 是一个用于查看用户登录失败记录的实用工具。

当直接运行 lastb 命令时,默认会读取系统日志文件 /var/log/btmp,并列出所有尝试登录但失败的用户信息。

命令格式

lastb [-adRx][-f ][-n ][用户名...][终端编号...]

常用选项

options:

  • -R 忽略主机列的输出
  • -a 在最后列显示用户的登录来源(主机名或IP)
  • -d 将IP地址解析为主机名显示。
  • -f 指定要读取的日志文件。
  • -n或- 限制输出的行数。
  • -R 不显示远程主机名或IP地址。
  • -x 显示系统的重启、关机及运行级别变化信息。

username:

  • username:仅显示特定用户 username 的失败登录记录。

tty:

  • tty 指定特定的终端设备进行查询。例如:last 0 等同于 last tty0。

使用示例

查看所有失败的登录尝试:

# lastb 
...
zgg      ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)
zgg      ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)
zf       ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)
za       ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)
zeng     ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)
zf       ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)
zette    ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)
z310     ssh:notty    143.198.176.57   Thu Apr  7 11:27 - 11:27  (00:00)

btmp begins Fri Apr 1 07:38:45 2025

仅显示前5条失败登录记录:

# lastb -n 5
mos      ssh:notty    194.31.98.204    Thu Apr 28 16:52 - 16:52  (00:00)
user     ssh:notty    194.31.98.204    Thu Apr 28 16:52 - 16:52  (00:00)
user     ssh:notty    194.31.98.204    Thu Apr 28 16:52 - 16:52  (00:00)
user     ssh:notty    194.31.98.204    Thu Apr 28 16:52 - 16:52  (00:00)
user     ssh:notty    194.31.98.204    Thu Apr 28 16:52 - 16:52  (00:00)

btmp begins Fri Apr 1 07:38:45 2025