为什么80%的码农都做不了架构师?>>>
DenyHosts官方网站为:http://denyhosts.sourceforge.net
1. 安装
- [root@localhost ~]# wget -c http://nchc.dl.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz
- [root@localhost ~]# ls DenyHosts-2.6.tar.gz
- DenyHosts-2.6.tar.gz
- [root@localhost ~]# tar zxf DenyHosts-2.6.tar.gz
- [root@localhost ~]# cd DenyHosts-2.6
- [root@localhost DenyHosts-2.6]# python setup.py install
- [root@localhost DenyHosts-2.6]# cd /usr/share/denyhosts/
- [root@localhost denyhosts]# ls
- CHANGELOG.txt denyhosts.cfg-dist plugins scripts
- daemon-control-dist LICENSE.txt README.txt setup.py
# tar -zxvf DenyHosts-2.6.tar.gz
# cd DenyHosts-2.6
# python setup.py install
默认是安装到/usr/share/denyhosts目录的。
2. 配置
# cd /usr/share/denyhosts/
# cp denyhosts.cfg-dist denyhosts.cfg
# vi denyhosts.cfg
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 = #设置管理员邮件地址
DAEMON_LOG = /var/log/denyhosts #自己的日志文件
DAEMON_PURGE = 10m #该项与PURGE_DENY 设置成一样,也是清除hosts.deniedssh 用户的时间。
3. 设置启动脚本
# cp daemon-control-dist daemon-control
# chown root daemon-control
# chmod 700 daemon-control
完了之后执行daemon-contron start就可以了。
# ./daemon-control start
如果要使DenyHosts每次重起后自动启动还需做如下设置:
ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts #建立符号链接
chkconfig --add denyhosts #增加denyhosts服务进程
chkconfig denyhosts on #设置开机启动denyhosts
chkconfig --list denyhosts
denyhosts 0:off 1:off 2:on 3:on 4:on 5:on 6:off
然后就可以启动了:
# service denyhosts start
可以看看/etc/hosts.deny内是否有禁止的IP,有的话说明已经成功了。
查看记录
cat /etc/hosts.deny