CentOS 下 SSH 起不来一般是 sshd 没装 / 没开 / 配置错 / 端口被挡 / 权限不对 这几类原因。可以按下面顺序一步步排查。
CentOS 7 / 8 / Stream 一般用 systemd:
systemctl status sshd
如果提示 Unit sshd.service could not be found,说明 sshd 可能没装。
rpm -qa | grep openssh-server
如果没有输出:
yum install -y openssh-server
systemctl start sshd
systemctl enable sshd
再看状态:
systemctl status sshd
journalctl -xe
# 或
systemctl status sshd -l
常见错误:
chown root:root /var/empty/sshd
chmod 711 /var/empty/sshd
ssh-keygen -A
systemctl restart sshd
firewall-cmd --list-all
没开就加:
firewall-cmd --add-service=ssh --permanent
firewall-cmd --reload
临时测试:
setenforce 0
如果这样能起来:
restorecon -Rv /etc/ssh
sshd -t
有错误会直接提示哪一行有问题。
-p 端口 登录systemctl status sshd
sshd -t
journalctl -xe
firewall-cmd --list-all
如果你愿意,可以把下面命令的输出贴出来,我直接帮你判断:
systemctl status sshd
journalctl -xe | tail -n 30
sshd -t