红联Linux门户
Linux帮助

Linux中系统户登录和操作日志的记录

发布时间:2016-03-04 15:14:34来源:linux网站作者:IT农夫

用户登录退出的日志记录在:/var/log/secure


如果需要记录每个用户执行过哪些命令等操作的记录,在/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 700 /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 700 /var/log/history/${LOGNAME}/*history* 2>/dev/null


本文永久更新地址:http://www.linuxdiyf.com/linux/18619.html