Denyhosts简介
当linux服务器暴露在互联网中,服务器将会遭到互联网上的扫描软件进行扫描,并试图猜测SSH登录口令,分析日志可见每天会有多条SSH登录失败纪录。
DenyHosts是Python语言写的一个程序,可以阻止试图猜测SSH登录口令,它会分析/var/log/secure等日志文件,当发现同一IP在进行多次SSH密码尝试时就会记录IP到/etc/hosts.deny文件,从而达到自动屏蔽该IP的目的。
官网/下载
DenyHosts官网:http://denyhosts.sourceforge.net/
解压安装
# 官网下载包安装
[root@www ~]# tar zxvf DenyHosts-2.6.tar.gz [root@www ~]# cd DenyHosts-2.6 [root@www DenyHosts-2.6]# yum install python -y [root@www DenyHosts-2.6]# python setup.py install [root@www DenyHosts-2.6]# cd /usr/share/denyhosts/ [root@www denyhosts]# cp denyhosts.cfg-dist denyhosts.cfg //配置文件 [root@www denyhosts]# cp daemon-control-dist daemon-control //启动文件 [root@www denyhosts]# chown root daemon-control [root@www denyhosts]# chmod 700 daemon-control
# yum安装
[root@www ~]# yum install -y denyhosts
配置文件
[root@www denyhosts]# vi denyhosts.cfg SECURE_LOG = /var/log/secure #ssh日志文件 # format is: i[dhwmy] # Where i is an integer (eg. 7) # m = minutes # h = hours # d = days # w = weeks # y = years # # never purge: PURGE_DENY = 50m #过多久后清除已阻止IP HOSTS_DENY = /etc/hosts.deny #将阻止IP写入到hosts.deny BLOCK_SERVICE = sshd #阻止服务名 PURGE_THRESHOLD = #定义了某一IP最多被解封多少次。某IP暴力破解SSH密码被阻止/解封达到了PURGE_THRESHOLD次,则会被永久禁止; DENY_THRESHOLD_INVALID = 1 #允许无效用户登录失败的次数 DENY_THRESHOLD_VALID = 10 #允许普通用户登录失败的次数 DENY_THRESHOLD_ROOT = 5 #允许root登录失败的次数 WORK_DIR = /usr/local/share/denyhosts/data #将deny的host或ip纪录到Work_dir中 DENY_THRESHOLD_RESTRICTED = 1 #设定 deny host 写入到该资料夹 LOCK_FILE = /var/lock/subsys/denyhosts #将DenyHOts启动的pid纪录到LOCK_FILE中,已确保服务正确启动,防止同时启动多个服务。 HOSTNAME_LOOKUP=NO #是否做域名反解 ADMIN_EMAIL = #设置管理员邮件地址 DAEMON_LOG = /var/log/denyhosts #DenyHosts日志位置
ps:配置文件内容根据自己需要自行调整
启动自启动服务
# ./daemon-control start #启动DenyHosts # ln -s /usr/share/denyhosts/daemon-control /etc/init.d //对daemon-control进行软连接,方便管理 # /etc/init.d/daemon-control start //启动denyhosts # chkconfig daemon-control on //将denghosts设成开机启动
或者
# vi /etc/rc.local --------->加入下面这条命令: /usr/share/denyhosts/daemon-control start
查看hosts.deny文件,找到攻击ip的记录
# vi /etc/hosts.deny
http://www.savh.cn/thread-1220.htm
转载请注明:Savh.Cn 发表