正在加载...

PS:Linux用户操作记录一般通过命令history来查看历史记录,但是如果因为某人误操作了删除了重要的数据,这种情况下history命令就不会有什么作用了。以下方法可以实现通过记录登陆IP地址和所有用户登录所操作的日志记录!

在/etc/profile配置文件的末尾加入以下脚本代码就可以实现,下面脚本是我网上找来的,原作者不知。但原脚本的时间变量有错误,不能记录时间,本人测试发现并检查修正:

PS1="`whoami`@`hostname`:"'[$PWD]'
history
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d /tmp/history ]
then
mkdir /tmp/history
chmod 777 /tmp/history
fi
if [ ! -d /tmp/history/${LOGNAME} ]
then
mkdir /tmp/history/${LOGNAME}
chmod 300 /tmp/history/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +"%Y%m%d_%H%M%S"`
export HISTFILE="/tmp/history/${LOGNAME}/${USER_IP} history.$DT"
chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null

通过上面的代码可以看出来,在系统的/tmp新建个history目录(这个目录可以自定义),在目录中记录了所有的登陆过系统的用户和IP地址,这也是监测系统安全的方法之一。

脚本自动生成的记录文件如下:

: http://www.ha97.com/4733.html

本文相关评论 - 才 2 条评论
rh204
2012-08-20 13:18:30
Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

你好,我也安装了9,可是到这里就卡了:Attempting to mount media :/dev/sr0
Attempting to mount media :/dev/sda1
Attempting to mount media :/dev/sda2
很明显问题是处在硬盘扫描上了,前面是Looking for the cdrom
我硬盘检测了没错误,而且以前也安装OPENSUSE UBUNUT FEDORA等LINUX发行版,也装过SABAYON 8,这次不知道怎么回事情,于是我尝试用虚拟机安装,虚拟机很正常因为进建立的VDI是空的硬盘,不知道什么原因,让人费解。你能帮我解释下么,高人。我换了一台机器也是如此,我用USB盘作的启动盘没有刻盘,为了环保。谢谢,请及时回复我的EAMIL,等

2013-03-13 09:58:43
Internet Explorer 6.0 Internet Explorer 6.0 Windows XP Windows XP

博主你好,如何在此基础上,把具体命令的操作结果记录呢?比如我vi时dd了一行记录,但是history显示的只是vi 文件,没有具体的操作记录