要提升CentOS SSH的安全性,可以采取以下措施:
更改默认SSH端口:
/etc/ssh/sshd_config。#Port 22 这一行,取消注释并修改为一个非标准端口,例如 Port 2222。systemctl restart sshd。禁用root登录:
/etc/ssh/sshd_config 文件中找到 PermitRootLogin 这一行。no,即 PermitRootLogin no。使用公钥认证:
ssh-keygen。~/.ssh/authorized_keys 文件中。/etc/ssh/sshd_config 文件,确保 PubkeyAuthentication yes。PasswordAuthentication no。限制SSH访问:
firewall-cmd 命令添加规则:firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="2222" accept'
firewall-cmd --reload
使用Fail2Ban:
yum install fail2ban。更新SSH版本:
yum update openssh-server 更新SSH服务器。使用SELinux:
日志审计:
/var/log/secure,以监控和审计登录尝试和其他安全相关事件。通过实施这些措施,可以显著提高CentOS SSH服务器的安全性。请根据实际情况选择适合的措施,并确保在进行任何更改之前备份相关配置文件。