# 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.linh.eu.org/jian-zhan-ji-shu/vps-kai-qi-root-yong-hu-deng-lu-ssh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
