温馨提示×

ubuntu ssh怎么重启

小樊
43
2026-09-16 05:06:45
栏目: 智能运维

在 Ubuntu 上“重启 SSH”通常指的是重启 SSH 服务(sshd),不同版本和系统初始化方式略有区别,下面是最常用的方法:


一、使用 systemd(Ubuntu 16.04 及以后,推荐)

sudo systemctl restart ssh

其他常用命令:

sudo systemctl status ssh      # 查看状态
sudo systemctl stop ssh        # 停止
sudo systemctl start ssh       # 启动
sudo systemctl enable ssh      # 开机自启

老版本 Ubuntu 服务名可能是 sshsshd,如果 ssh 不行可试:

sudo systemctl restart sshd

二、使用 service 命令(兼容旧系统)

sudo service ssh restart

三、如果是最小系统 / 容器(无 systemd)

sudo /etc/init.d/ssh restart

四、确认 SSH 是否在运行

ps aux | grep sshd

sudo systemctl is-active ssh

五、常见注意事项

  • 不要断开当前 SSH 连接后再重启,否则可能连不回去
  • 修改了 /etc/ssh/sshd_config 后必须重启才生效
  • 如果连不上,检查防火墙:
sudo ufw status

如果你是想:

  • 重启 SSH 客户端
  • 重启 服务器本身
  • 或修改 SSH 配置后不生效

可以告诉我具体场景,我帮你更精准处理。

0