Record all operations command once the user's login logout

 Adding these elements to the / etc / bashrc file

####################### 设置history 历史命令########################
#定义 .bash_history 文件中保存命令的记录数
HISTFILESIZE=4000
#history 输出命令的个数
HISTSIZE=4000
#定义时间格式
HISTTIMEFORMAT='%F %T '
export HISTTIMEFORMAT

 

 

Record and save each logged-in user's operation details

Records login details of the user's operation, and save the file contents to a file /usr/share/.history,

Save the form of hidden files

Use ls -al command to view the saved content

Add the following in / etc / profile in

################ 记录用户的登录,ip地址,shell命令,操作时间 并保存到文件中 ###############
#history
#获得ip
USER_IP=`who -u am i 2>/dev/null | awk '{print $NF}' | sed -e 's/[()]//g'`
HISTDIR=/usr/share/.history
if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
if [ ! -d $HISTDIR ]
then
mkdir -p $HISTDIR
chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
then
mkdir -p $HISTDIR/${LOGNAME}
chmod 300 $HISTDIR/${LOGNAME}
fi
export HISTSIZE=4000
DT=`date +%Y%m%d_%H%M%S`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.history.$DT"
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S] "
chmod 600 $HISTDIR/${LOGNAME}/*.history* 2>/dev/null

 Execution. / Etc / profile file

 

Published 24 original articles · won praise 7 · views 8235

Guess you like

Origin blog.csdn.net/yang_zzu/article/details/104240668