在 Ubuntu 上查看 SSH 服务状态,常用以下几种方法(适用于大多数 Ubuntu 版本,如 20.04 / 22.04 / 24.04):
sudo systemctl status ssh
常见输出说明:
active (running) ✅ → SSH 正在运行inactive (dead) ❌ → SSH 未运行enabled → 开机自启disabled → 未设置开机自启ss -lntp | grep 22
或
sudo netstat -lntp | grep 22
如果看到类似:
LISTEN 0 128 0.0.0.0:22
说明 SSH 正在监听 22 端口。
ps aux | grep sshd
如果看到 sshd 进程,说明 SSH 服务已启动。
sudo ufw status
如果看到:
22/tcp ALLOW Anywhere
说明防火墙允许 SSH。
若未放行,可添加:
sudo ufw allow ssh
dpkg -l | grep openssh-server
如果未安装:
sudo apt update
sudo apt install openssh-server
sudo systemctl start ssh # 启动
sudo systemctl stop ssh # 停止
sudo systemctl restart ssh # 重启
sudo systemctl enable ssh # 设置开机自启
systemctl is-active ssh
输出:
active ✅inactive ❌如果你是在 WSL / 云服务器 / 本地虚拟机 环境中,我也可以帮你针对具体场景排查 SSH 问题。