在 CentOS 上遇到 SSH 被拒绝(Connection refused / Permission denied),常见原因和排查思路如下:
通常表示 目标端口没开或没监听
systemctl status sshd
若未运行:
systemctl start sshd
systemctl enable sshd
rpm -q openssh-server
未安装则:
yum install -y openssh-server
查看配置:
grep Port /etc/ssh/sshd_config
连接时需指定端口:
ssh -p 端口号 user@ip
firewall-cmd --list-all
放行 SSH:
firewall-cmd --add-service=ssh --permanent
firewall-cmd --reload
getenforce
可临时测试:
setenforce 0
通常表示 连上了,但登录失败
ssh user@ip
grep PermitRootLogin /etc/ssh/sshd_config
若为 no,需用普通用户登录。
~/.ssh/authorized_keyschmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
grep PasswordAuthentication /etc/ssh/sshd_config
若为 no,只能用密钥。
ping ip
telnet ip 22
ping iptelnet ip 22systemctl status sshdfirewall-cmd --list-all/var/log/secure如果你能提供 具体报错信息(如 Connection refused 还是 Permission denied),我可以更精准帮你定位。