Centos7-跟蹤用戶操作記錄並錄入日志


1. 添加bash全局配置文件:

cd /etc/profile.d

sudo -e vi log_command.sh

輸入如下內容:

export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'

2. 添加rsyslog配置文件bash.conf:

sudo -e /etc/rsyslog.d/bash.conf

填寫如下內容:

local6.*    /var/log/commands.log

3. 重啟rsyslog服務:

sudo systemctl restart rsyslog

4. 添加logrotate文件

cd /etc/logrotate.d

vi syslog

添加一行:

/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
/var/log/commands.log

/var/log/commands.log
{
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM