last命令 – 显示用户历史登录情况

标签:,
来源: 老季博客
日期: 2022-12-20
作者: 腾讯云/服务器VPS推荐评测/Vultr
阅读数: 46

last命令的功能是用于显示用户历史登录情况,通过查看系统记录的日志文件内容,进而使管理员可以获知谁曾经或者试图连接过服务器。

通过读取系统登陆历史日志文件(/var/log/wtmp)并按照用户名、登录终端、来源终端、时间等信息进行划分,让用户对系统历史登录情况一目了然。

语法格式:last [选项]

常用参数:

-n 显示行数
-a 将来源终端信息项放置放到最后
-R 省略来源终端
-d 将IP地址转换成主机名称
-f 指定记录文件
-x 显示系统开关机等信息

参考实例

显示近期用户或终端的历史登录情况:

[root@jiloc ~]# last  
root     tty2         tty2             Mon Oct 17 03:13    
gone - no logout  reboot   system boot  4.18.0-80.el8.x8 Mon Oct 17 03:05   still running  
root     tty2         tty2             Mon Oct 17 03:00 - 03:05  (00:05)  reboot   
system boot  4.18.0-80.el8.x8 Mon Oct 17 02:59 - 03:05  (00:06)    
wtmp begins Mon Oct 17 02:59:19 2022 

仅显示最近3条历史登录情况,并不显示来源终端信息:

[root@jiloc ~]# last -n 3 -R  
root     tty2         Mon Oct 17 03:13    gone - no logout  reboot   
system boot  Mon Oct 17 03:05   still running  root     tty2         
Mon Oct 17 03:00 - 03:05  (00:05)    
wtmp begins Mon Oct 17 02:59:19 2022 

显示系统的开关机历史信息,并将来源终端放置到最后面:

[root@jiloc ~]# last -x -a   
root     tty2         Mon Oct 17 03:13    
gone - no logout  tty2  runlevel (to lvl 5)   Mon Oct 17 03:06   still running      4.18.0-80.el8.x86_64  reboot   
system boot  Mon Oct 17 03:05   still running    
4.18.0-80.el8.x86_64  shutdown system down  Mon Oct 17 03:05 - 03:05  (00:00)     4.18.0-80.el8.x86_64  
root     tty2         Mon Oct 17 03:00 - 03:05  (00:05)     
tty2  runlevel (to lvl 5)   Mon Oct 17 02:59 - 03:05  (00:05)     4.18.0-80.el8.x86_64  reboot   
system boot  Mon Oct 17 02:59 - 03:05  (00:06)     
4.18.0-80.el8.x86_64    wtmp begins Mon Oct 17 02:59:19 2022 
链接到文章: https://jiloc.com/48140.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注