1、查看所有尝试登录记录:cat /var/log/secure
cat /var/log/secure | awk ‘/Failed/{print $(NF-3)}’ | sort | uniq -c | awk ‘{print $2″ = “$1;}’
下载denyhost:wget http://cdnetworks-kr-1.dl.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz
tar -zxvf DenyHosts-2.6.tar.gz
cd DenyHosts-2.6
python setup.py install
cd /usr/share/denyhosts/
cp denyhosts.cfg-dist denyhosts.cfg
vi denyhosts.cfg
SECURE_LOG = /var/log/secure
#ssh 日志文件,它是根据这个文件来判断的。
HOSTS_DENY = /etc/hosts.deny
#控制用户登陆的文件
PURGE_DENY = 5m
#过多久后清除已经禁止的
BLOCK_SERVICE = sshd
#禁止的服务名
DENY_THRESHOLD_INVALID = 1
#允许无效用户失败的次数
DENY_THRESHOLD_VALID = 5
#允许普通用户登陆失败的次数
DENY_THRESHOLD_ROOT = 5
#允许root登陆失败的次数
HOSTNAME_LOOKUP=NO
#是否做域名反解
ADMIN_EMAIL =
#管理员邮件地址,它会给管理员发邮件
DAEMON_LOG = /var/log/denyhosts
#自己的日志文件
cp /usr/share/denyhosts/daemon-control-dist daemon-control
chown root daemon-control
chmod 700 daemon-control
ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts
chkconfig denyhosts on