Linux实时记录用户执行的命令

Step1:修改profile文件

export HISTFILE="/var/log/his/$(date '+%F').his"
export HISTTIMEFORMAT='%F %T '
export PROMPT_COMMAND='user=$(who am i | sed "s/[ ][ ]*/ /g"); history 1 | { read x date time cmd; echo "${date} ${time} ${user} ${cmd}"; } >> $HISTFILE'

Step2:创建日志目录并且设置权限

[root@rhel ~]# mkdir -p /var/log/his

Step3:查看生成的日志

[root@rhel his]# ls -l
total 16
-rw-r--r-- 1 rhel rhel 12496 Dec 10 20:46 2019-12-10.his

posted on 2019-12-10 20:47  CyberSecurityBook  阅读(361)  评论(0)    收藏  举报

导航