1,修改/etc/profile文件
[root@CentOS7-2 ~]# 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=4096
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
2,使/etc/profile生效
[root@CentOS7-2 ~]# source /etc/profile
3,查看
[root@CentOS7-2 ~]# ll /var/log/history/
total 0
d-wx------ 2 root root 6 Jun 1 13:02 root
本文详细介绍如何在CentOS系统中配置个人用户的历史命令记录,包括修改profile文件以记录每个用户的详细操作历史,确保所有历史命令都保存在各自的日志目录下,并设置适当的权限。
4142

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



