在 Ubuntu 中,默认情况下 root 用户是禁用 SSH 登录的,这是为了增加系统安全性。
![](https://img-blog.csdnimg.cn/direct/7cc73b2c79e94d26b78e7ea65b1833a2.png)
一、修改配置
找到 PermitRootLogin 行:在文件中找到 PermitRootLogin 配置项。默认情况下,它通常被设置为 PermitRootLogin prohibit-password 或 PermitRootLogin without-password。
bash
sudo vim /etc/ssh/sshd_config
![](https://img-blog.csdnimg.cn/direct/544cb12ae14e47ff995a72b6aea71340.png)
修改完成之后,记得保存。
二、重启服务
只有在重启了 SSH 服务之后,配置才会最终生效。完成配置后,你就可以通过 root 用户连接到 SSH 了。
bash
sudo systemctl restart ssh