关于linux:linux系统下记录用户操作历史

2次阅读

共计 599 个字符,预计需要花费 2 分钟才能阅读完成。

集体博客: 点击这里进入

  • 编辑 /etc/profile 文件开端增加下列代码, 增加实现后保留退出
  • 执行命令:source /etc/profile,退出以后终端,
  • 之后会在 /var/log/history 目录下以用户名、IP 地址、登录工夫为文件名生成一个文件
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
正文完
 0