Linux 監控root用戶登錄並發送郵件


1、安裝mailx

yum  install  mailx -y

2、配置/etc/mail.rc文件

set from=yourname@126.com
set smtp=smtps://smtp.126.com:465
set smtp-auth-user=yourname@126.com
set smtp-auth-password=n7876KhMpp8676uM
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

3、創建證書

mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.126.com:465 | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p‘ > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
cd  /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt

4、root用戶的.bashrc 文件中添加告警腳本

echo "$(whoami) login at: $(date +"%F %T") ip address: $(w|sed -n '3p'|awk '{print$3}')" | mail -s root yourmail@qq.com

 


免責聲明!

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



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