要在 Debian 系统上通过修改 sshd_config
文件并使用命令一键开启 root 登录,可以按照以下步骤进行:
一键开启 root 登录的命令
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo systemctl restart ssh
详细步骤
-
修改
sshd_config
文件使用
sed
命令来编辑/etc/ssh/sshd_config
文件,取消对PermitRootLogin
和PasswordAuthentication
行的注释并设置它们的值:sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
-
这两条命令分别完成以下操作:
- 将
#PermitRootLogin prohibit-password
修改为PermitRootLogin yes
- 将
#PasswordAuthentication yes
修改为PasswordAuthentication yes
- 将
-
重启 SSH 服务
使配置更改生效,重启 SSH 服务:
sudo systemctl restart ssh
示例命令总结
将以上步骤合并成一个命令序列:
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && sudo systemctl restart ssh
设置 root 密码
如果 root 用户没有设置密码,确保你已经为 root 用户设置了密码:
sudo passwd root
-
注意事项
-
安全性:允许 root 用户通过 SSH 登录存在安全风险,强烈建议使用强密码或设置基于密钥的认证。
-
备份配置:在修改配置文件之前,最好备份一下原始文件:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
- 限制 IP 地址:如果必须允许 root 登录,考虑限制允许的 IP 地址,提高安全性。
-
-
没有回复内容