一,编写脚本/root/bin/checkip.sh,每5分钟检查一次,如果发现通过ssh登录失败 次数超过10次,自动将此远程IP放入Tcp Wrapper的黑名单中予以禁止防问
#!/bin/bash
#
#*************************************
#author: liangmingyong
#QQ: 515291006
#email: 515291006@qq.com
#version: 1.0
#date: 2020-07-05
#description: The test script
#*************************************
grep sshd /var/log/secure |awk '/Failed/{print $(NF-3)}'|sort |uniq -c |sort >>/root/ssherror.log
while read count ip;do
if [ $count -gt 10 ];then
echo "sshd:$ip" >> /etc/hosts.deny
fi
done < /root/ssherror.log
#写入计划任务中
*/5 * * * * root sh /root/bin/checkip.sh &> /dev/null
二, 配置magedu用户的sudo权限,允许magedu用户拥有root权限