CentOS 7 openssh安全加固方案参考—— 筑梦之路

1. 禁止root登陆

# /etc/ssh/sshd_config
PermitRootLogin no

2. 禁止使用密码登陆

# /etc/ssh/sshd_config
PasswordAuthentication no
PubkeyAuthentication yes
AuthenticationMethods publickey

3. 修改默认端口

# /etc/ssh/sshd_config
Port 32456

4. 限制访问来源

使用 TCP Wrapper 和防火墙等方式,控制可以访问 OpenSSH 服务器的来源网络和 IP,避免非法访问。例如,在 /etc/hosts.allow 中添加受信任的 IP 列表

# /etc/hosts.allow
sshd: 192.168.0.0/255.255.255.0
sshd: 10.0.0.0/255.255.255.0

5. 开启会话超时

开启 SSH 会话超时是一种非常好的保护方法。在 sshd_config 文件中,将 ClientAliveInterval 属性设置为 300,并将 ClientAliveCountMax 属性设置为 0

# /etc/ssh/sshd_config
ClientAliveInterval 300
ClientAliveCountMax 0

6. 配置 SSH 安全协议

SSH 安全协议的版本号会影响实际的安全性,因此有必要针对实际情况进行配置。在 sshd_config 中,添加以下属性:

# /etc/ssh/sshd_config
Protocol 2
KexAlgorithms [email protected],diffie-hellman-group-exchange-sha256
Ciphers [email protected],[email protected],[email protected]
MACs [email protected],[email protected],[email protected]

其中,Protocol 属性设置为 2,表示只使用 SSH 协议版本 2。KexAlgorithms 属性设置加密算法,Ciphers 属性设置数据加密算法,MACs 属性设置完整性算法,以上设置可以根据实际的需求和算法的安全性进行选择。

其他说明

安装最新的补丁:及时安装最新的安全补丁,修复已知的漏洞和安全问题。同时,使用最新的操作系统和软件版本,可以提升 OpenSSH 服务的安全性。

其他措施:在 OpenSSH 服务器上定期监测系统日志,及时处理异常情况。同时,提高用户或管理员的安全意识,避免密码泄露或疏忽造成的安全漏洞。

猜你喜欢

转载自blog.csdn.net/qq_34777982/article/details/130890020