加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux 监控root用户登录并发送邮件

发布时间:2020-12-14 01:44:24 所属栏目:Linux 来源:网络整理
导读:1、安装mailx yum? install? mailx -y 2、配置/etc/mail.rc文件 set from [email?protected] .comset smtp =smtps://smtp.126.com:465 set smtp [email?protected] .comset smtp -auth-password= n7XJ3KhMppm4T6uMset smtp -auth= loginset ssl -verify= ign

1、安装mailx

yum? install? mailx -y

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

set from[email?protected].com
set smtp=smtps://smtp.126.com:465
set smtp[email?protected].com
set smtp-auth-password=n7XJ3KhMppm4T6uM
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 [email?protected]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读