顺子の杂货铺
生命不息,折腾不止,且行且珍惜~

Linux审计脚本

DMIT VPS

有时候遇到主机上的数据莫名被rm的情况,而且还没人承认,
那么就需要在系统上加个审计记录操作日志,方便追溯。
这样锅就不用你来背了,脚本如下:

cat /etc/profile
PS1="whoami@hostname:"'[$PWD]'
history
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_IP}_history.$DT"
chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null
赞(0)
未经允许不得转载:順子の杂货铺 » Linux审计脚本
搬瓦工VPS

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

分享创造快乐

联系我们联系我们