Red Hat服务器安全配置:SSH服务配置与暴力破解防护
在Linux系统安全防护中,SSH服务是最常被攻击的端口之一。本文将结合Red Hat系统环境,提供一套完整的SSH安全配置方案,有效防范暴力破解攻击。
1. 基础SSH配置优化
首先,编辑SSH配置文件:
sudo vim /etc/ssh/sshd_config
关键配置项修改如下:
# 禁用root直接登录
PermitRootLogin no
# 修改默认端口(建议使用非22端口)
Port 2222
# 禁用密码认证,仅允许密钥认证
PasswordAuthentication no
PubkeyAuthentication yes
# 设置最大尝试次数
MaxAuthTries 3
# 禁用空密码
PermitEmptyPasswords no
修改完成后重启SSH服务:
sudo systemctl restart sshd
2. Fail2ban暴力破解防护
安装并配置fail2ban:
sudo yum install fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
编辑jail.local文件,添加SSH防护规则:
[sshd]
enabled = true
port = 2222
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 3600
ignoreip = 127.0.0.1/8
启动fail2ban服务:
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
3. IPtables防火墙规则
配置iptables限制SSH访问:
# 允许已建立连接的流量
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# 只允许特定IP段访问SSH端口
iptables -A INPUT -p tcp --dport 2222 -s 192.168.1.0/24 -j ACCEPT
# 拒绝其他所有SSH请求
iptables -A INPUT -p tcp --dport 2222 -j DROP
保存规则:
sudo iptables-save > /etc/sysconfig/iptables
4. 验证配置
检查SSH服务状态:
sudo sshd -T | grep -E "(port|permitrootlogin|passwordauthentication)"
查看fail2ban状态:
sudo fail2ban-client status sshd
通过以上配置,可有效降低SSH服务被暴力破解的风险,确保Red Hat服务器的安全性。

讨论