本文最后更新于7 天前,其中的信息可能已经过时,如有错误请发送邮件到898599301@qq.com
开启 SSH 密码登录
前提:能进入root
第 1 步:密钥登录服务器,设置 root 密码
sudo passwd root
第 2 步:修改 SSH 配置
nano /etc/ssh/sshd_config
找到以下两行(可以用 Ctrl + W 搜索),改成:
PasswordAuthentication yes
PermitRootLogin yes
如果前面有
#号,把#删掉。
第 3 步:检查有没有覆盖配置
ls /etc/ssh/sshd_config.d/
如果里面有文件(比如 50-cloud-init.conf),也要检查:
cat /etc/ssh/sshd_config.d/*.conf
如果看到 PasswordAuthentication no,改掉它:
nano /etc/ssh/sshd_config.d/50-cloud-init.conf
把 PasswordAuthentication no 改成 PasswordAuthentication yes。
第 4 步:重启 SSH 服务
systemctl restart ssh
第 6 步:测试密码登录
不要关当前窗口! 另开一个 PowerShell 窗口测试:
ssh root@服务器ip地址
输入密码,能登进去就成功了 ✅