温馨提示×

centos怎样查看ssh状态

小樊
44
2026-07-19 07:49:25
栏目: 智能运维

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


✅ 方法一:使用 systemctl(最常用)

systemctl status sshd

常见输出说明:

  • active (running) ✅ SSH 服务正在运行
  • inactive (dead) ❌ SSH 服务未运行
  • enabled ✅ 开机自启
  • disabled ❌ 未设置开机自启

✅ 方法二:查看 SSH 是否正在监听端口

ss -lntp | grep ssh

netstat -lntp | grep ssh

如果看到类似:

LISTEN 0 128 0.0.0.0:22

说明 SSH 正在监听 22 端口


✅ 方法三:查看 SSH 进程

ps -ef | grep sshd

如果有 sshd 进程,说明服务已启动。


✅ 方法四:检查 SSH 是否开机自启

systemctl is-enabled sshd
  • enabled
  • disabled

✅ 启动 / 停止 / 重启 SSH(补充)

# 启动
systemctl start sshd

# 停止
systemctl stop sshd

# 重启
systemctl restart sshd

# 设置开机自启
systemctl enable sshd

✅ CentOS 6(老系统,init)

service sshd status

如果你是想 排查 SSH 无法连接的问题,我也可以帮你一步步检查防火墙、端口、配置文件(/etc/ssh/sshd_config)等。

0