debian系统SSH一键开启root登录-服务器论坛-综合交流区-资源工坊-游戏模组资源分享

debian系统SSH一键开启root登录

要在 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

详细步骤

  1. 修改 sshd_config 文件

    使用 sed 命令来编辑 /etc/ssh/sshd_config 文件,取消对 PermitRootLoginPasswordAuthentication 行的注释并设置它们的值:

    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
    1. 这两条命令分别完成以下操作:

      • #PermitRootLogin prohibit-password 修改为 PermitRootLogin yes
      • #PasswordAuthentication yes 修改为 PasswordAuthentication yes
    2. 重启 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

       

    3. 注意事项

      1. 安全性:允许 root 用户通过 SSH 登录存在安全风险,强烈建议使用强密码或设置基于密钥的认证。

      2. 备份配置:在修改配置文件之前,最好备份一下原始文件:

        sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
      3. 限制 IP 地址:如果必须允许 root 登录,考虑限制允许的 IP 地址,提高安全性。
请登录后发表评论

    没有回复内容