如何查找谁重新启动了Linux系统

时间:2020-03-21 11:43:43  来源:igfitidea点击:

本简要教程说明了如何查找谁重新启动了Linux系统。
对于正在管理具有许多用户的共享服务器的用户来说,此技巧很有用。
要了解谁重新启动了Linux服务器,我们需要安装psacct实用程序,该实用程序用于监视用户的活动。

安装psacct之后,运行以下命令以查找谁重新引导了Linux服务器:

$lastcomm reboot

输出示例为:

reboot sk pts/0 0.00 secs Mon Apr 3 15:05
reboot S X root __ 0.00 secs Mon Apr 3 15:00
reboot sk pts/0 0.00 secs Mon Apr 3 15:00

如上所示,名为“ sk”的用户已于本地时间4月2日星期一15:05从“ pts0”执行了“ reboot”命令。

等等,我们还没有完成。

上面的命令仅显示先前重新引导的三个结果。
我们可以通过运行以下命令来显示完整的重启历史记录。
请注意,它不会显示谁重新启动了系统。
相反,它将仅显示上一次重新启动的日期和时间。

$last reboot

输出示例:

reboot system boot 3.10.0-327.22.2. Mon Apr 3 15:06 - 15:12 (00:06) 
reboot system boot 3.10.0-327.22.2. Mon Apr 3 15:04 - 15:12 (00:08) 
reboot system boot 3.10.0-327.22.2. Mon Apr 3 15:01 - 15:12 (00:11) 
reboot system boot 3.10.0-327.22.2. Mon Apr 3 14:44 - 15:00 (00:16) 
reboot system boot 3.10.0-327.22.2. Sat Apr 1 14:35 - 18:42 (04:06) 
reboot system boot 3.10.0-327.22.2. Fri Mar 31 14:35 - 14:43 (00:07) 
reboot system boot 3.10.0-327.22.2. Fri Mar 31 13:05 - 13:12 (00:07) 
reboot system boot 3.10.0-327.22.2. Fri Mar 31 12:46 - 13:04 (00:18) 
reboot system boot 3.10.0-327.22.2. Fri Mar 31 12:40 - 12:46 (00:05) 
reboot system boot 3.10.0-327.22.2. Tue Mar 28 17:23 - 19:32 (02:08) 
reboot system boot 3.10.0-327.22.2. Tue Mar 28 14:59 - 19:32 (04:33) 
reboot system boot 3.10.0-327.22.2. Thu Mar 23 17:08 - 17:41 (00:32) 
reboot system boot 3.10.0-327.22.2. Thu Mar 23 17:06 - 17:08 (00:01) 
reboot system boot 3.10.0-327.22.2. Thu Mar 23 16:24 - 17:04 (00:40) 
reboot system boot 3.10.0-327.22.2. Thu Mar 23 16:00 - 17:04 (01:03)

另外,我们可以通过查看BASH历史记录文件来找出哪个用户重新启动了Linux机器。

$grep reboot /home/*/.bash_history

上面的命令将查看所有用户.bash_history文件,并显示谁重新启动了系统。

/home/sk/.bash_history:reboot
/home/sk/.bash_history:sudo reboot
/home/sk/.bash_history:reboot 
/home/sk/.bash_history:sudo reboot 
/home/sk/.bash_history:sudo reboot 
/home/sk/.bash_history:reboot

要搜索特定用户,只需提及用户名,如下所示。

$grep reboot /home/sk/.bash_history

该命令将仅查看属于名为“ sk”的用户的.bash_history文件。
始终建议注意所有用户的活动。
我们永远都不知道谁会破坏系统。
保持定期更改root用户的密码。
限制用户对Linux系统的访问,并为用户设置密码策略,以避免任何安全漏洞。