温馨提示×

CentOS怎么查看SSH状态

小樊
50
2026-07-07 23:14:31
栏目: 智能运维

CentOS 上查看 SSH(sshd)服务状态,常用方法如下(适用于 CentOS 7/8/Stream,使用 systemd):


一、查看 SSH 服务状态(最常用)

systemctl status sshd

常见状态说明:

  • active (running) ✅ 正常运行
  • inactive (dead) ❌ 未运行
  • failed ❌ 启动失败(可查看日志)

二、查看 SSH 是否开机自启

systemctl is-enabled sshd
  • enabled:开机自启
  • disabled:未自启

三、启动 / 停止 / 重启 SSH

# 启动
systemctl start sshd

# 停止
systemctl stop sshd

# 重启
systemctl restart sshd

四、查看 SSH 是否在监听端口

ss -lntp | grep sshd

netstat -lntp | grep sshd

默认端口一般是 22


五、查看 SSH 服务日志(排错很有用)

journalctl -u sshd

查看实时日志:

journalctl -u sshd -f

六、确认 SSH 配置文件是否正确

sshd -t

无输出表示配置正常。


七、CentOS 6(老系统,不推荐)

service sshd status

✅ 快速检查清单

systemctl status sshd
ss -lntp | grep 22

如果你遇到 SSH 连不上 / 端口不通 / 启动失败,可以把报错贴出来,我可以帮你具体排查。

0