denyhosts是python语言程序,借用tcp_wrapper程序来进行主机防护。作用:防止暴力破解服务器用户密码。 1.安装 # cd /usr/local DenyHosts-2.6.tar.gz # tar -zxvf DenyHosts-2.6.tar.gz # cd DenyHosts-2.5 # python setup.py install 默认是安装到/usr/share/denyhosts目录 2.配置 # cd /usr/share/denyhosts/ # cp denyhosts.cfg-dist denyhosts.cfg # vi denyhosts.cfg 相关参数解释: ############ THESE SETTINGS ARE REQUIRED ############ SECURE_LOG = /var/log/secure HOSTS_DENY = /etc/hosts.deny PURGE_DENY = 1w #过多久后清除已经禁止的,其中w代表周,d代表天,h代表小时,s代表秒,m代表分钟 BLOCK_SERVICE = sshd DENY_THRESHOLD_INVALID = 3 #允许无效用户失败的次数 DENY_THRESHOLD_VALID = 5 #允许普通用户登陆失败的次数 DENY_THRESHOLD_ROOT = 5 #允许root登陆失败的次数 DENY_THRESHOLD_RESTRICTED = 1 WORK_DIR = /usr/share/denyhosts/data SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES HOSTNAME_LOOKUP=YES LOCK_FILE = /var/lock/subsys/denyhosts ############ THESE SETTINGS ARE OPTIONAL ############ ADMIN_EMAIL = denyhosts@163.com #若有ip被禁用发邮件通知 SMTP_HOST = localhost SMTP_PORT = 25 SMTP_FROM = DenyHosts <192.168.0.1@localhost> SMTP_SUBJECT = DenyHosts Report AGE_RESET_VALID=1d #有效用户登录失败计数归零的时间 AGE_RESET_ROOT=1d #root用户登录失败计数归零的时间 AGE_RESET_RESTRICTED=1d AGE_RESET_INVALID=10d #无效用户登录失败计数归零的时间 ######### THESE SETTINGS ARE SPECIFIC TO DAEMON MODE ########## DAEMON_LOG = /var/log/denyhosts DAEMON_SLEEP = 30s DAEMON_PURGE = 1h 登录denyhosts@163.com邮箱查看是否有IP被禁用。###################################################### 设置启动脚本 # cp daemon-control-dist daemon-control # chown root daemon-control # chmod 700 daemon-control #./daemon-control start (启动) #ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts #chkconfig --add denyhosts #chkconfig --list denyhosts #chkconfig denyhosts on 设置开机启动 # vi /etc/rc.local 添加/usr/share/denyhosts/daemon-control start 3.启动服务 service denyhosts start 4. denyhos使用 如果不想让主机拒绝某一个ip,做法如下: vi /etc/hosts.allow sshd: 192.168.0.1 #允许192.168.0.1访问该主机的ssh服务 如果想拒绝某一个ip同样使用vi /etc/hosts.deny添加就Ok (责任编辑:IT) |