当前位置: 首页IT技术 → 多人登录追究误操作登记

多人登录追究误操作登记

更多

在linux系统的环境下,不管是root用户还是其它的用户只有登陆系统后用进入操作我们都可以通过命令history来查看历史记录,可是假如一台服务器多人登陆,一天因为某人误操作了删除了重要的数据。这时候通过查看历史记录(命令:history)是没有什么意义了。那有没有什么办法实现通过记录登陆后的IP地址和某用户名所操作的历史记录呢?答案:有的。

通过在/etc/profile里面加入以下代码就可以实现:

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/dbasky ]

then

mkdir /tmp/dbasky

chmod 777 /tmp/dbasky

fi

if [ ! -d /tmp/dbasky/${LOGNAME} ]

then

mkdir /tmp/dbasky/${LOGNAME}

chmod 300 /tmp/dbasky/${LOGNAME}

fi

if [ ! -d /tmp/dbasky/${LOGNAME}/SIP=${USER_IP}.txt ]

then

touch /tmp/dbasky/${LOGNAME}/SIP=${USER_IP}.txt

chmod 600 /tmp/dbasky/${LOGNAME}/SIP=${USER_IP}.txt

fi

export HISTSIZE=4096

#DT=`date "+%Y%m%d_%H%M%S"`

export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky"

chmod 600 /tmp/dbasky/${LOGNAME}/*dbasky 2>/dev/null

if [ -a "/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky" ]

then

cat "/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky" | perl -pe 's/(/d+)/localtime($1)/e' >> /tmp/dbasky/${LOGNAME}/SIP=${USER_IP}.txt

fi

其实通过上面的代码不能看出来,在系统的/tmp新建个dbasky目录,在目录中记录了所有的登陆过系统的用户和IP地址,是不是觉得很方便呢?我们还可以用这个方法来监测系统的安全性。

热门评论
最新评论
昵称:
表情: 高兴 可 汗 我不要 害羞 好 下下下 送花 屎 亲亲
字数: 0/500 (您的评论需要经过审核才能显示)