yum install”@Chinese support”
linux 记录那个用户登录系统,并做了什么操作,
vi /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 /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}@${USER_IP}_history.$DT"
chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null
EOF
[root@server ~]# source /etc/profile
[root@server ~]# logout
本文介绍了一种在Linux系统中记录用户登录及操作的方法。通过修改/etc/profile文件,利用whoami和who命令获取当前登录用户的名称及IP地址,并设置历史记录文件的位置与权限。这种方法有助于管理员监控用户活动。
1372

被折叠的 条评论
为什么被折叠?



