centOS为SSH登录设置电子邮件提醒
以root用户为例:
vim /root/.bashrc
echo 'xx被人登录' `date` `who` | mail -s "阿里云服务器被登录" xx@163.com (收件邮箱)
安装mailx
yum install mailx -y
vim /etc/mail.rc
写入:
set from=12312120@qq.com (发件邮箱)
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=12312120@qq.com
set smtp-auth-password=你的 QQ 邮箱授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
#配置QQ邮箱的SSL证书
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.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
为了防止出现前文所说的发送邮件警告提示,还需要进入邮箱 SSL 证书存放目录 /root/.certs 里执行如下命令:
cd /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
Notice: Trust flag u is set automatically if the private key is present.出现这句就可以