有些開放外網端口的主機,瘋狂的遭遇密碼嘗試***,雖然密碼設置的較爲複雜,可是長時間的密碼嘗試會給/var/logs/secure寫入大量日誌,從而也會增長系統負擔。fail2ban就能夠很好的解決這個問題,設置最大嘗試的次數,當超過指定次數時,fail2ban會調用iptables把嘗試探測的IP加入到黑名單,而且鎖定一斷時間,次數和鎖定時間能夠根據本身設置,須要啓動iptables,如下是一鍵配置腳本:python
#!/bin/bash #author by thundermeng #mail:thundermeng@live.cn #Install fail2ban wget http://soft.kwx.gd/security/fail2ban-0.8.4.tar.bz2 tar xfj fail2ban-0.8.4.tar.bz2 cd fail2ban-0.8.4 python setup.py install cd files cp ./redhat-initd /etc/init.d/fail2ban chkconfig fail2ban on #Configuration sed -i '/\[ssh-iptables\]/{n;n;s/enabled = false/enabled = true/}' /etc/fail2ban/jail.conf sed -ri '/^\[ssh-iptables\]$/,/^\[ssh-ddos\]$/{s#(logpath =).*#\1 /var/log/secure#}' /etc/fail2ban/jail.conf /etc/init.d/iptables start /etc/init.d/fail2ban start fail2ban-client status iptables -L