1、编写脚本/root/bin/checkip.sh,每5分钟检查一次,如果发现通过ssh登录失败 次数超过10次,自动将此远程IP放入Tcp Wrapper的黑名单中
[root@centos7 data]#vim checkip.sh #!/bin/bash warning=10 file_ip=/data/ip.log lastb |awk '!/^btmp|^$/{print $3}' |sort |uniq -c >/data/ip.log while read line;do num=`echo $line |awk '{print $1}'` ip=`echo $line |awk '{print $2}'` if [ $num -gt $warning ];then echo "sshd:$ip" >> /etc/hosts.deny fi done <$file_ip [root@centos7 ~]#crontab -e */5 * * * * /bin/bash /data/checkip.sh2、配置magedu用户的sudo权限,允许magedu用户拥有root权限
[root@centos7 sudoers.d]#vim magedu magedu ALL=(root) ALL