Linux记录每个用户不同会话登录后的所有操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux记录每个用户不同会话登录后的所有操作相关的知识,希望对你有一定的参考价值。
为记录每个用户对应的操作,利于事后查询 .修改/etc/profile,添加如下代码
vim /etc/profile
history
USER=`whoami`
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 /var/log/history ]; then
mkdir /var/log/history
chmod 777 /var/log/history
fi
if [ ! -d /var/log/history/${LOGNAME} ]; then
mkdir /var/log/history/${LOGNAME}
chmod 300 /var/log/history/${LOGNAME}
fi
export HISTSIZE=40960
DT=`date +"%Y%m%d_%H:%M:%S"`
export HISTFILE="/var/log/history/${LOGNAME}/${USER}@${USER_IP}_$DT"
chmod 600 /var/log/history/${LOGNAME}/*history* 2>/dev/null
以上是关于Linux记录每个用户不同会话登录后的所有操作的主要内容,如果未能解决你的问题,请参考以下文章