This commit is contained in:
moac 2024-05-16 19:55:30 +08:00
parent 9a5442f197
commit 86615f3c24
2 changed files with 29 additions and 28 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -1,30 +1,31 @@
--- +++
title: 开启root远程登录Linux title = 'Linux启用root远程登录'
date: 2021-04-14 11:38:32.0 date = 2024-02-02T10:47:18+08:00
updated: 2022-09-13 09:40:06.804 draft = false
url: /archives/permitrootlogin
categories:
- Linux
tags:
- Linux
---
设置root密码 +++
```
sudo passwd 在Linux系统中要启用远程登录root并允许使用密码登录需要编辑SSH服务器的配置文件 /etc/ssh/sshd_config。
```
修改配置文件**sshd_config** 以下是步骤:
```
sudo vim /etc/ssh/sshd_config 1. 使用具有足够权限的用户如sudo用户通过SSH或终端登录到Linux服务器。
```
2. 打开SSH配置文件
```sh
sudo nano /etc/ssh/sshd_config
```
3. 修改以下配置项允许root用户远程登录将 PermitRootLogin 行改为 PermitRootLogin yes 或者 PermitRootLogin without-password (如果你打算使用密钥对验证而不是密码)。 注意:出于安全考虑,强烈建议使用公钥认证而非密码认证。如果禁用了密码登录,且希望重新启用密码登录,确保没有 PasswordAuthentication no 这一行或者将其注释掉,或者改为 PasswordAuthentication yes。
4. 保存并关闭配置文件: 在nano编辑器中按 Ctrl+X 然后按 Y 再按 Enter 来保存更改。
5. 重启SSH服务以应用新的配置
```sh
sudo systemctl restart sshd
```
6. 测试远程连接: 使用一个支持SSH的客户端尝试以root用户身份远程登录并输入root用户的密码。请务必注意允许root用户直接远程登录并通过密码验证是一项安全隐患通常不推荐在生产环境中这样做。更安全的做法是使用公钥认证结合sudo或其他权限管理机制。
修改这两条并保存
```
PermitRootLogin yes
PasswordAuthentication yes
```
重载sshd
```
sudo systemctl reload sshd
```
重新连接即可使用root权限远程连接