doc/笔记/开启root远程登录Linux-permitrootl...

32 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

+++
title = 'Linux启用root远程登录'
date = 2024-02-02T10:47:18+08:00
draft = false
+++
在Linux系统中要启用远程登录root并允许使用密码登录需要编辑SSH服务器的配置文件 /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或其他权限管理机制。