温馨提示×

centos怎样重启ssh服务

小樊
49
2026-09-08 17:29:28
栏目: 智能运维

在 CentOS 中重启 SSH 服务,常用方法取决于系统版本(CentOS 6 及以前用 service / init.d,CentOS 7 及以后用 systemctl)。

1. CentOS 7 / 8 / Stream(推荐)

sudo systemctl restart sshd

查看状态:

sudo systemctl status sshd

设置开机自启(可选):

sudo systemctl enable sshd

2. CentOS 6 及更早版本

sudo service sshd restart

或

sudo /etc/init.d/sshd restart

3. 修改配置后重启(常见场景)

如果你改了 /etc/ssh/sshd_config,要先检查配置再重启:

sudo sshd -t
sudo systemctl restart sshd

4. 注意事项

  • 服务名是 sshd(不是 ssh)
  • 远程操作时,确保不要断开当前连接前先测试新配置
  • 防火墙若开启,确认 22 端口放行:
    sudo firewall-cmd --list-all
    

如果你告诉我你的 CentOS 版本,我可以给更精确的命令。

0 踩