如果你服务器被入侵了,该怎么做才能让自己第一时间知晓?本文将教您实现,服务器被人登录之后第一时间通知你。其实我自己没想到/etc/profile文件的特殊之处 ,进行配置脚本生效source /etc/profile
脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #!/bin/bash # auto email # 2021年5月20日13:56:44 # Email 2911811868@qq.com # by author limaolin ################################### if ! rpm -q mailx >/dev/unll;then yum install mailx -yum cat >>/etc/mail.rc<<-EOF set from=2911811686@qq.com #设置发送邮件地址 set smtp=smtp.qq.com #设置邮件地址服务器 set smtp-auth-user=2911811686@qq.com #设置认证邮件用户 set smtp-auth-password=sde22dxqqlwxc #设置认证邮件密码 EOF else echo Successfuly fi if [ ! -f /usr/local/bin/jq ];then wget -c http://stedolan.github.io/jq/download/linux64/jq -O /usr/local/bin/jq chmod o+x /usr/local/bin/jq else echo Successfuly fi curl -s https://www.ip.cn/ip/`ifconfig eth0 |grep broadcast |awk '{print $2}'`.html |grep -E "tab0_address"|awk -F">" '{print "远程服务器地址: " $2}'|sed 's@</div@@g' >/opt/ssh.logs IP1=`cat /opt/ssh.logs` IP2=`ifconfig eth0 |grep broadcast |awk '{print "登记远程IP地址: " $2}'` IP3=`curl -s https://ip.taobao.com/outGetIpInfo?ip=${SSH_CLIENT%% *} |jq .|grep -Eia "country|isp_id|queryIp|city|ip|isp|region_id|region|country_id|city_id"|sed 's/,//g;s/:/=/g;s/"//g'|sed "s#country_id#国家代码#g;s#city_id#市编号#g;s#region_id#省编号#g;s#isp_id#ISP服务商编号#g;s#isp#ISP服务商名称#g;s#city#市名称#g;s#region#省名称#g;s#country#国家#g;s#ip#查询的IP地址#g;s#queryIp#登入IP地址#g"` echo "$IP1 ${IP2} ${IP3}" |mail -s "您服务器有人登录SSH" 2911811686@qq.com |
echo /root/auto-mail.v.01.sh >>/etc/profile
source /etc/profile #让脚本生效
如果有黑客破密码解成功第一时间收到报警信息
「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」
上一篇:没有了,已经是最后文章
下一篇:Docker的历史