码迷,mamicode.com
首页 > 系统相关 > 详细

linux 记录所有系统用户bash操作日志

时间:2020-06-17 10:43:12      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:int   dir   inux   chmod   user   port   目录   登录系统   root用户   

记录所有用户登录系统的任何操作日志,以便有据可查。

1.编辑 /etc/profile文件

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
  1. 加载文件生效
source /etc/profile

/var/log/history 日志的存放位置,该目录下以每个用户为名创建一个文件夹,每次用户退出后都会产生以用户名、登录IP、时间的日志文件,以及用户本次的所有操作。
root用户不记录在此。

linux 记录所有系统用户bash操作日志

标签:int   dir   inux   chmod   user   port   目录   登录系统   root用户   

原文地址:https://blog.51cto.com/xushaojie/2505116

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!