Chinaunix首页 | 论坛 | 博客
  • 博客访问: 422689
  • 博文数量: 55
  • 博客积分: 2331
  • 博客等级: 大尉
  • 技术积分: 605
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-26 12:03
文章分类

全部博文(55)

文章存档

2011年(2)

2010年(53)

我的朋友

分类: 网络与安全

2010-09-10 15:06:47

你的linux服务器暴露在互联网之中,该服务器将会遭到互联网上的扫描软件进行骚描,并试图猜测SSH登录口令。
 
你会发现,每天会有多条SSH登录失败纪录。那些扫描工具将对你的服务器构成威胁,你必须设置复杂登录口令,并将尝试多次登录失败的IP给阻止掉,让其在一段时间内不能访问该服务器。
 
用DenyHosts可以阻止试图猜测SSH登录口令,它会分析/var/log/secure等日志文件,当发现同一IP在进行多次SSH密码尝试时就会记录IP到/etc/hosts.deny文件,从而达到自动屏蔽该IP的目的。
 
DenyHosts官方网站为:
 
DenyHosts安装
 

# tar -zxvf DenyHosts-2.6.tar.gz
# cd DenyHosts-2.6
# python setup.py install


DenyHosts参数配置
 
 

# cd /usr/share/denyhosts/             # DenyHosts默认安装目录
# cp denyhosts.cfg-dist denyhosts.cfg
# vi denyhosts.cfg                     # DenyHosts配置文件

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                        #阻止服务名
                                                                                                      
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 = root@data.com                 #设置管理员邮件地址  
                                                                 
DAEMON_LOG = /var/log/denyhosts             #自己的日志文件  
DAEMON_PURGE = 10m                          #该项与PURGE_DENY 设置成一样,也是清除
                                             hosts.deniedssh 用户的时间。

DenyHosts启动文件配置

# cp daemon-control-dist daemon-control
# chown root daemon-control
# chmod 700 daemon-control

# ./daemon-control     #DenyHosts命令格式

Usage: ./daemon-control {start [args...] | stop | restart [args...] | status | debug | condrestart [args...] }
 
For a list of valid args refer to:
$ denyhosts.py --help
 
# ./daemon-control start                   #启动DenyHosts
starting DenyHosts:    /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfg

如果要使DenyHosts每次重起后自动启动还需做如下设置:

# ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts
# chkconfig --add denyhosts
# chkconfig denyhosts on

# chkconfig –level 2345 denyhosts on

或者修改/etc/rc.local文件:


# vi /etc/rc.local
加入下面这条命令
/usr/share/denyhosts/daemon-control start

阅读(1695) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~