1、編寫腳本/root/bin/checkip.sh校镐,每5分鐘檢查一次剩愧,如果發(fā)現(xiàn)通過ssh登錄失敗?次數(shù)超過10次冬筒,自動將此遠程IP放入Tcp?Wrapper的黑名單中予以禁止防問
將腳本添加計劃任務
? ? crontab -e
? ? */5 * * * *? /bin/bash?/root/bin/checkip.sh &> /dev/null
#!/bin/bash
grep -i? 'failed password' /var/log/secure|awk -F" " '{countip[$11]++}END{for(i in countip)if(countip[i] > 10){print i}}' > ip_ssh.txt
while read ip;do
? ? ? grep $ip /etc/hosts.deny &> /dev/null? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? if [ $? -eq 0 ];then
? ? ? ? continue
? else
? ? ? ? echo sshd:$ip >> /etc/hosts.deny
? fi
done < ip_ssh.txt
2瞪慧、配置magedu用戶的sudo權(quán)限髓考,允許magedu用戶擁有root權(quán)限
? ? 編輯sudoers文件vim? /etc/sudoers,添加magedu? ALL=(ALL)? ALL?行配置