centos安装denyhosts
最近不知道得罪了哪路大神,一直都有坏人暴力破解本站的SSH登录密码。想安安静静的写博客就这么难么…没办法,那就安个denyhosts吧。
centos下直接使用Yum安装即可:yum install denyhosts.noarch
当然也可以下载编译安装。安装好后,配置文件是/etc/denyhosts.conf
,参数说明如下:
SECURE_LOG = /var/log/secure#ssh日志文件
HOSTS_DENY = /etc/hosts.deny #将阻止IP写入到hosts.deny
PURGE_DENY =30m#过多久后清除已阻止IP
BLOCK_SERVICE = sshd#阻止服务名
DENY_THRESHOLD_INVALID = 5//允许无效用户(在/etc/passwd未列出)登录失败次数,允许无效用户登录失败的次数.
DENY_THRESHOLD_VALID = 10#允许普通用户登录失败的次数
DENY_THRESHOLD_ROOT = 1//允许root登录失败的次数
DENY_THRESHOLD_RESTRICTED = 1#设定 deny host 写入到该资料夹
WORK_DIR = /usr/share/denyhosts/data #将deny的host或ip纪录到Work_dir中
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES
HOSTNAME_LOOKUP=YES #是否做域名反解
LOCK_FILE = /var/lock/subsys/denyhosts #将DenyHOts启动的pid纪录到LOCK_FILE中,已确保服务正确启动,防止同时启动多个服务。
ADMIN_EMAIL = a@b.com #设置管理员邮件地址
SMTP_HOST = localhost
SMTP_PORT = 25
SMTP_FROM = DenyHosts nobody@localhost
SMTP_SUBJECT = DenyHosts Report
AGE_RESET_VALID=5d
AGE_RESET_ROOT=25d
AGE_RESET_RESTRICTED=25d
AGE_RESET_INVALID=10d
DAEMON_LOG = /var/log/denyhosts#自己的日志文件
DAEMON_SLEEP = 30s
DAEMON_PURGE = 1h#该项与PURGE_DENY 设置成一样,也是清除hosts.deniedssh 用户的时间
配置完成后,启动服务并设置开机启动:
service denyhosts start
chkconfig denyhosts on
然后查看 /etc/hosts.deny
文件,发现里面已经有记录了:
[root@miss_yi ~]# tail /etc/hosts.deny
# DenyHosts: Mon Oct 20 17:19:38 2014 | ALL: 74.221.172.28
ALL: 74.221.172.28
# DenyHosts: Mon Oct 20 17:19:38 2014 | ALL: 117.21.173.175
ALL: 117.21.173.175
# DenyHosts: Mon Oct 20 17:19:38 2014 | ALL: 112.78.3.196
ALL: 112.78.3.196
# DenyHosts: Mon Oct 20 17:19:38 2014 | ALL: 181.143.230.74
ALL: 181.143.230.74
# DenyHosts: Mon Oct 20 17:19:38 2014 | ALL: 216.151.221.194
ALL: 216.151.221.194
[root@miss_yi ~]# wc /etc/hosts.deny
771 4628 30294 /etc/hosts.deny