在 CentOS 上遇到 SSH 报错 很常见,但“报错”有很多种,需要先看具体报错信息。下面我先给你一个常见 SSH 问题排查清单,你可以对照自己的情况;如果你愿意,把具体报错内容贴出来,我可以精准帮你分析。
ssh user@ip)systemctl start sshd)cat /etc/redhat-release
原因:SSH 服务没开 / 端口不对 / 防火墙拦了
✅ 排查:
systemctl status sshd
netstat -tunlp | grep 22
✅ 解决:
systemctl start sshd
systemctl enable sshd
防火墙:
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
原因:
✅ 检查:
grep -E "PasswordAuthentication|PubkeyAuthentication" /etc/ssh/sshd_config
✅ 修改后重启:
systemctl restart sshd
原因:网络不通 / IP 错 / 被防火墙 DROP
✅ 测试:
ping x.x.x.x
telnet x.x.x.x 22
原因:服务器重装 / IP 复用
✅ 解决(客户端):
ssh-keygen -R x.x.x.x
原因:权限异常
✅ 修复:
chown root:root /var/empty/sshd
chmod 711 /var/empty/sshd
systemctl restart sshd
可能是 SELinux 问题:
setenforce 0
systemctl restart sshd
systemctl status sshd
ss -tunlp | grep :22
iptables -L -n | grep 22
getenforce
请直接贴:
系统版本:
报错完整信息:
你执行的命令:
我可以一步一步带你修,甚至判断是不是被云厂商安全组拦了。