您的位置:首页 > 运维架构 > Linux

【Linux】一步一步学Linux——lastb命令(99)

2019-08-03 10:35 971 查看
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons

00. 目录

文章目录

01. 命令概述

lastb命令用于显示用户错误的登录列表,此指令可以发现系统的登录异常。单独执行lastb命令,它会读取位于

/var/log
目录下,名称为btmp的文件,并把该文件内容记录的登入失败的用户名单,全部显示出来。

02. 命令格式

lastb [选项] [参数]

03. 常用选项

lastb 与last命令类似,lastb命令查找、var/log/btmp 文件,此文件列出了所有登录系统失败的用户的信息

必要参数
-n 显示最近登录信息的行数
-t 根据登陆的时间显示指定用户的登录状态
-R 简略显示主机名区域
-a 在最后一列显示主机名称
-d 对于非本地登录的用户,将显示的IP地址转换为主机名
-i 类似于“-d” 的选项,将显示的主机名称转换为IP地址
-o 读取旧的类型的wtmp 文件
-x 显示系统登录等级
--help 显示帮助信息
--version 显示版本显示

04. 参考示例

4.1 列出登入失败的用户记录

[root@itcast ~]# lastb
root     pts/1                         Fri Aug  2 21:00 - 21:00  (00:00)
root     pts/1                         Thu Aug  1 21:27 - 21:27  (00:00)

btmp begins Thu Aug  1 21:27:11 2019
[root@itcast ~]#

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

4.2 使用-a参数把IP显示在最后列

[root@itcast ~]# lastb -a
root     pts/1        Fri Aug  2 21:00 - 21:00  (00:00)
root     pts/1        Thu Aug  1 21:27 - 21:27  (00:00)

btmp begins Thu Aug  1 21:27:11 2019
[root@itcast ~]#

4.3 使用-R参数不显示主机名和IP信息

[root@itcast ~]# lastb -R
root     pts/1        Fri Aug  2 21:00 - 21:00  (00:00)
root     pts/1        Thu Aug  1 21:27 - 21:27  (00:00)

btmp begins Thu Aug  1 21:27:11 2019
[root@itcast ~]#

4.4 显示6条登录失败的信息

[root@itcast ~]# lastb -6
root     pts/1                         Fri Aug  2 21:00 - 21:00  (00:00)
root     pts/1                         Thu Aug  1 21:27 - 21:27  (00:00)

btmp begins Thu Aug  1 21:27:11 2019
[root@itcast ~]#

4.5 显示3条登录失败的信息

[root@itcast ~]# lastb -n 3
root     pts/1                         Fri Aug  2 21:00 - 21:00  (00:00)
root     pts/1                         Thu Aug  1 21:27 - 21:27  (00:00)

btmp begins Thu Aug  1 21:27:11 2019
[root@itcast ~]#

4.6 显示2条关于root用户登录失败的信息

[root@itcast ~]# lastb -n 2 root
root     pts/1                         Fri Aug  2 21:00 - 21:00  (00:00)
root     pts/1                         Thu Aug  1 21:27 - 21:27  (00:00)

btmp begins Thu Aug  1 21:27:11 2019
[root@itcast ~]#

05. 附录

参考:【Linux】一步一步学Linux系列教程汇总

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: