先用密钥ssh登录云服务器
方案一(推荐):
sudo -ipasswd #设置root密码,输入两遍mkdir -p /etc/ssh/sshd_config.d printf 'PermitRootLogin yes\nPasswordAuthentication yes\n' \ > /etc/ssh/sshd_config.d/00-allow-root-password.conf chmod 600 /etc/ssh/sshd_config.d/00-allow-root-password.conf # 关键前置检查:主配置里没有 Include 的话,drop-in 文件根本不会被读 grep -qi '^Include.*sshd_config.d' /etc/ssh/sshd_config \ && echo "[OK] Include 存在" \ || echo "[!!] 主配置无 Include,drop-in 不生效,需改用 sed 方式" sshd -t && systemctl restart ssh sshd -T | grep -Ei '^permitrootlogin|^passwordauthentication'方案二:
sudo -ipasswd #设置root密码,输入两遍sudo vi /etc/ssh/sshd_config#按“i”进入编辑状态
找到:
PermitRootLogin prohibit-password
改为:
PermitRootLogin yes
找到:
PasswordAuthentication no
改为:
PasswordAuthentication yes
编辑完后按“ESC”退出编辑状态,输入“:wq”保存
systemctl restart sshd #重启 ssh #systemctl restart ssh #ubuntu系统使用此命令注意:甲骨文云机器要额外修改/etc/ssh/sshd_config.d/60-cloudimg-settings.conf,把PasswordAuthentication no改为PasswordAuthentication yes
sudo vi /etc/ssh/sshd_config.d/60-cloudimg-settings.conf按“i”进入编辑状态
找到:
PasswordAuthentication no
改为:
PasswordAuthentication yes
#编辑完后按“ESC”退出编辑状态,输入“:wq”保存
systemctl restart ssh #重启sshEND