1、编写脚本/root/bin/checkip.sh,每5分钟检查一次,如果发现通过ssh登录失败次数超过10次,自动将此远程IP放入Tcp Wrapper的黑名单中予以禁止防问
[root@test ~]#cat /root/bin/checkip.sh
#!/bin/bash
n=10
grep "sshd" /var/log/secure|cut -d: -f4|awk '/Failed/{print $(NF-3)}'sort |uniq -c |sort |grep "[0-9]" >>ssh_failed.log
while read count ip;do
if [ ${count} > ${n} ];then
echo "sshd is from:${ip}" >>/etc/hosts.deny
fi
done < ssh_failed.log
#写入计划任务中
[root@test ~]#crontab -e
*/5 * * * * root sh /root/bin/checkip.sh &>/dev/null 2>&1
2、配置magedu用户的sudo权限,允许magedu用户拥有root权限
[root@test ~]#visudo
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
magedu ALL=(ALL) ALL #添加此行