
我需要一種方法來審核指定使用者在與我的伺服器的 ssh 連線中鍵入的命令。
有幫助嗎?
答案1
如果使用者不是故意隱藏他們的活動,這樣的事情會起作用嗎?
cat ~/.bash_history | grep "name_of_command"
或者
cat /home/user_name_here/.bash_history | grep search_string
儘管啟用 PAM(可插入身份驗證模組)TTY 審核可能是更好的解決方案: pam_tty_audit.8
安裝auditd
(注意:確保已安裝 ssh 伺服器)並重新啟動:
sudo apt-get install auditd && sudo reboot
刪除任何 pam_tty_audit:
sed '/pam_tty_audit.so disable=/d' /etc/pam.d/sshd
將啟用字串附加到 pam.d 設定檔:
sudo sh -c "echo 'session required pam_tty_audit.so enable=*' >> /etc/pam.d/sshd"
開始審計:
sudo service auditd status
如果沒有運行:
sudo service auditd start
grep tty 報告使用者 UID:
sudo aureport --tty | grep $(id -u username_here)
相關閱讀:
https://serverfault.com/questions/336217/how-do-i-log-every-command-executed-by-a-user
http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html