1、編寫腳本/root/bin/checkip.sh,每5分鐘檢查一次,如果發現通過ssh登錄失敗 次數超過10次,自動將此遠程IP放入Tcp Wrapper的黑名單中予以禁止防問
[root@C76 ~]# cat /root/bin/checkip.sh
#!/bin/bash
n=10
cat /var/log/secure |grep sshd|awk '/Failed/{print $(NF-3)}'|sort |uniq -c |sort >>ssherro.log
while read count ip;do
if [ ${count} > ${n} ];then
echo "sshd is from:${ip}" >>/etc/hosts.deny
fi
done < ssherro.log
#寫入計劃任務中
crontab -e
*/5 * * * * root sh /root/bin/checkip.sh &>/dev/null
2、配置magedu用戶的sudo權限,允許magedu用戶擁有root權限
visudo
root ALL=(ALL) ALL #在此行後添加
magedu ALL=(ALL) ALL ##添加此行