美文网首页
centos7 记录所有用户历史操作

centos7 记录所有用户历史操作

作者: 热血大桃子 | 来源:发表于2019-05-28 18:47 被阅读0次

在centos7 中虽然可以使用history查看历史操作,但是仅限于当前登录用户的历史操作,如果多人使用一台服务器,就必须记录多用户的操作记录了,找了一个方法如下:

  • /etc/profile 文件末尾加上如下内容
export PS1='[\u@\h \w]# '
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 /opt/history ]
then
mkdir /opt/history
chmod 777 /opt/history
fi
if [ ! -d /opt/history/${LOGNAME} ]
then
mkdir /opt/history/${LOGNAME}
chmod 300 /opt/history/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +"%Y%m%d_%H%M%S"`
export HISTFILE="/opt/history/${LOGNAME}/${USER_IP} history.$DT"
chmod 600 /opt/history/${LOGNAME}/*history* 2>/dev/null
  • 然后 source /etc/profile使配置生效,然后可以在/opt目录下看到一个名为history的文件,里面包含了以多个用户名命名的文件夹(只有相应登录过得用户才有记录),然后就可以快乐的查看人家到底做了什么事情了。

相关文章

网友评论

      本文标题:centos7 记录所有用户历史操作

      本文链接:https://www.haomeiwen.com/subject/dfljtctx.html