> For the complete documentation index, see [llms.txt](https://book.linh.eu.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.linh.eu.org/jian-zhan-ji-shu/vps-kai-qi-root-yong-hu-deng-lu-ssh.md).

# VPS开启root用户登录SSH

如果预设只能用密钥登录VPS，则可以进行以下操作。

1.切换到root：

```
sudo -i
```

2.修改SSH配置文件/etc/ssh/sshd\_config

```
nano /etc/ssh/sshd_config
```

3.修改PermitRootLogin和PasswordAuthentication为yes

```
# Authentication:
PermitRootLogin yes //默认为no，需要开启root用户访问改为yes
# Change to no to disable tunnelled clear text passwords
PasswordAuthentication yes //默认为no，改为yes开启密码登陆
```

4.设置root密码

```
passwd root
```

5.重启SSH

（1）debian系：

```
/etc/init.d/ssh restart
```

（2）centos系：

```
systemctl restart sshd.service
```
