Centos服务器配置DenyHost防暴力破解

简介: 背景:只要互联网上的服务器就会被恶意扫描或者暴力破解密码,一方面如果密码设置过于简单,服务器就会被入侵,另一方面服务器的资源开销也会增加。http://blog.daobidao.com/centos-server-denyhost-config.

背景:

只要互联网上的服务器就会被恶意扫描或者暴力破解密码,一方面如果密码设置过于简单,服务器就会被入侵,另一方面服务器的资源开销也会增加。
http://blog.daobidao.com/centos-server-denyhost-config.html

安装方法:

1、安装Denyhost程序

Centos 6 X64 安装:

[Bash:4.1] <#> wget -c https://raw.githubusercontent.com/jinchengjiang/shell-script/master/denyhosts/denyhosts-2.6-5.el6.rf.noarch.rpm
[Bash:4.1] <#> rpm -ivh denyhosts-2.6-5.el6.rf.noarch.rpm

Centos 7 X64 安装:

[Bash:4.1] <#> wget -c https://raw.githubusercontent.com/jinchengjiang/shell-script/master/denyhosts/denyhosts-2.6-5.el7.rf.noarch.rpm
[Bash:4.1] <#> rpm -ivh denyhosts-2.6-5.el7.rf.noarch.rpm

如果不会配置denyhost配置文件,可以参考下面的命令,下载现成的配置文件使用。

[Bash:4.1] <#> cd /etc/denyhosts/
[Bash:4.1] <#> mv denyhosts.cfg denyhosts.cfg.bak
[Bash:4.1] <#> wget -c https://raw.githubusercontent.com/jinchengjiang/shell-script/master/conf/denyhosts.cfg
[Bash:4.1] <#> chkconfig denyhosts on
[Bash:4.1] <#> /etc/init.d/denyhosts restart

2、如果需要配置Denyhost邮件通知,需要修改/etc/denyhosts/denyhosts.cfg的文件,具体的内容如下:

ADMIN_EMAIL: if you would like to receive emails regarding newly

restricted hosts and suspicious logins, set this address to

match your email address. If you do not want to receive these reports

leave this field blank (or run with the –noemail option)

Multiple email addresses can be delimited by a comma, eg:

ADMIN_EMAIL = foo@bar.com, bar@foo.com, etc@foobar.com

ADMIN_EMAIL= 通知给哪个邮箱

SMTP_HOST and SMTP_PORT: if DenyHosts is configured to email

reports (see ADMIN_EMAIL) then these settings specify the

email server address (SMTP_HOST) and the server port (SMTP_PORT)

SMTP_HOST= SMTP地址
SMTP_PORT= SMTP端口

SMTP_USERNAME and SMTP_PASSWORD: set these parameters if your

smtp email server requires authentication

SMTP_USERNAME= SMTP发件的邮箱
SMTP_PASSWORD= SMTP发件的邮箱密码

SMTP_FROM: you can specify the “From:” address in messages sent

from DenyHosts when it reports thwarted abuse attempts

SMTP_FROM = DenyHosts 发件人的名字

1、详细配置参数:

SECURE_LOG = /var/log/secure # 系统安全日志文件,主要获取ssh信息

HOSTS_DENY = /etc/hosts.deny # 拒绝写入IP文件 hosts.deny

PURGE_DENY = 4w # 过多久后清除已经禁止的,其中w代表周,d代表天,h代表小时,s代表秒,m代表分钟

PURGE_THRESHOLD = 6 # 定义了某一IP最多被解封多少次。即某一IP由于暴力破解SSH密码被阻止/解封达到了PURGE_THRESHOLD次,则会被永久禁止;

BLOCK_SERVICE = ALL # denyhosts所要阻止的服务名称或者所有

DENY_THRESHOLD_INVALID = 3 # 允许无效用户登录失败的次数

DENY_THRESHOLD_VALID = 10 # 允许普通用户登录失败的次数

DENY_THRESHOLD_ROOT = 6 # 允许ROOT用户登录失败的次数

DENY_THRESHOLD_RESTRICTED = 1 # 设定 deny host 写入到该资料夹

WORK_DIR = /var/lib/denyhosts # 将deny的host或ip纪录到Work_dir中

SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS = YES

HOSTNAME_LOOKUP = NO # 是否做主机名反向解析

LOCK_FILE = /var/lock/subsys/denyhosts # 将DenyHOts启动的pid纪录到LOCK_FILE中,已确保服务正确启动,防止同时启动多个服务

SMTP_SUBJECT = DenyHosts Report # 邮件标题

AGE_RESET_VALID = 5d # 有效用户登录失败计数归零的时间

AGE_RESET_ROOT = 25d # ROOT用户登录失败计数归零的时间

AGE_RESET_RESTRICTED = 25d # 用户的失败登录计数重置为0的时间(/usr/share/denyhosts/restricted-usernames)

AGE_RESET_INVALID = 10d # 无效用户登录失败计数归零的时间

DAEMON_LOG = /var/log/denyhosts

DAEMON_SLEEP = 30s

DAEMON_PURGE = 1h # 该项与PURGE_DENY 设置成一样,也是清除hosts.deniedssh 用户的时间

相关文章
|
6天前
|
存储 安全 Linux
新 CentOS 7 服务器的基本配置
新 CentOS 7 服务器的基本配置
14 1
|
15天前
|
运维 网络协议 Linux
揭秘CentOS 7:系统目录奥秘大起底,网卡配置秒变高手,让你的服务器管理飞一般的感觉!
【8月更文挑战第5天】CentOS 7作为RHEL的社区版本,以其稳定性和丰富功能广受好评。本文通过案例分析介绍其系统目录结构及网卡配置方法。系统目录如/(根)、/bin(基本命令)、/boot(启动文件)、/dev(设备文件)、/etc(配置文件)、/home(用户目录)和/lib(共享库)等各司其职。网卡配置通过编辑/etc/sysconfig/network-scripts/下的ifcfg文件实现,如设置ens33接口的静态IP地址、子网掩码、网关和DNS服务器,并通过重启网络服务使配置生效。这是系统管理员必备的技能之一。
26 2
|
5天前
|
网络协议 Linux Shell
如何在运行Centos 6的虚拟服务器上安装cPanel
如何在运行Centos 6的虚拟服务器上安装cPanel
9 0
|
5天前
|
关系型数据库 MySQL Linux
在 CentOS 7 服务器上安装和保护 phpMyAdmin 与 Apache 的方法
在 CentOS 7 服务器上安装和保护 phpMyAdmin 与 Apache 的方法
11 0
|
6天前
|
Linux 数据安全/隐私保护
在CentOS 7服务器上添加和删除用户的方法
在CentOS 7服务器上添加和删除用户的方法
6 0
|
1月前
|
弹性计算 安全 Ubuntu
新手3分钟1Panel安装教程,使用阿里云服务器CentOS操作系统
在阿里云CentOS 7.9服务器上安装1Panel面板,包括远程连接ECS、执行安装命令、设置安装目录(默认/opt)、开启20410端口、配置安全入口和用户密码。记得在阿里云安全组中开放20410端口以访问面板。
新手3分钟1Panel安装教程,使用阿里云服务器CentOS操作系统
|
1月前
|
缓存 Linux 开发工具
centos设置ntp服务同步目标服务器时间
【7 月更文挑战第 1天】linux+centos设置ntp服务同步目标服务器时间
|
2月前
|
NoSQL 关系型数据库 应用服务中间件
jdk1.8、mysql、redis、nginx centos云服务器安装配置
jdk1.8、mysql、redis、nginx centos云服务器安装配置
|
3月前
|
网络协议 物联网 Linux
你不能不知道的:无公网IP,SSH远程连接CentOS服务器【内网穿透】
你不能不知道的:无公网IP,SSH远程连接CentOS服务器【内网穿透】
187 0
|
3月前
|
存储 安全 网络协议
云服务器 Centos7 部署 Elasticsearch 8.0 + Kibana 8.0 指南
云服务器 Centos7 部署 Elasticsearch 8.0 + Kibana 8.0 指南
184 0