在 CentOS 上查看 SSH(sshd)服务状态,常用以下几种方式(适用于 CentOS 7/8/Stream,使用 systemd):
systemctl(最常用)systemctl status sshd
常见输出说明:
active (running) ✅ SSH 服务正在运行inactive (dead) ❌ SSH 服务未运行enabled ✅ 开机自启disabled ❌ 未设置开机自启ss -lntp | grep ssh
或
netstat -lntp | grep ssh
如果看到类似:
LISTEN 0 128 0.0.0.0:22
说明 SSH 正在监听 22 端口。
ps -ef | grep sshd
如果有 sshd 进程,说明服务已启动。
systemctl is-enabled sshd
enabled ✅disabled ❌# 启动
systemctl start sshd
# 停止
systemctl stop sshd
# 重启
systemctl restart sshd
# 设置开机自启
systemctl enable sshd
service sshd status
如果你是想 排查 SSH 无法连接的问题,我也可以帮你一步步检查防火墙、端口、配置文件(/etc/ssh/sshd_config)等。