登录
首页 >  文章 >  linux

查看Linux失败登录记录,lastb命令全解析

时间:2025-07-02 23:21:24 163浏览 收藏

从现在开始,我们要努力学习啦!今天我给大家带来《Linux失败登录记录查看方法-lastb命令详解》,感兴趣的朋友请继续看下去吧!下文中的内容我们主要会涉及到等等知识点,如果在阅读本文过程中有遇到不清楚的地方,欢迎留言呀!我们一起讨论,一起学习!

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 2022

仅显示前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 2022

到这里,我们也就讲完了《查看Linux失败登录记录,lastb命令全解析》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于Linux,命令,lastb,失败登录记录,/var/log/btmp的知识点!

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>