AWS RHEL9 无法远程连接 / RHEL6 ssh 到 RHEL9 no hostkey alg 错误

最近在aws 新购RHEL9 替换RHEL 6.8 机器,发现 2 个比较直观的问题:

问题 1:非 ec2-user 用户无法连接服务器(包括 root 和新增用户)

mac 电脑上远程连接错误信息:

[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

排查步骤与解决方案:

1. 检查 SSH 配置文件 /etc/ssh/sshd_config

    • 确保以下配置正确:
      PermitRootLogin yes
      PasswordAuthentication yes

      修改后重启 SSH:

      systemctl restart sshd

      重启后还是无法连接

      2. 检查 Include 配置项

      sshd_config 文件中发现:

      Include /etc/ssh/sshd_config.d/*.conf

      这意味着 SSH 还会加载 /etc/ssh/sshd_config.d/ 目录下的其他配置文件

      3. 找到 50-cloud-init.conf 影响 SSH 认证.

      发现 /etc/ssh/sshd_config.d/50-cloud-init.conf 中包含:

      PasswordAuthentication no

      解决方案:

      • no 改为 yesPasswordAuthentication yes
      • 重新启动 SSH 服务:systemctl restart sshd

      此时再次连接就正常

      问题 2:RHEL 6.8 服务器 SSH/SCP 连接 RHEL 9 云服务器时报错 no hostkey alg lost connection

      错误信息:

      no hostkey alg
      lost connection

      问题分析:

      经过排查发现,RHEL 9 默认系统加密策略 (DEFAULT) 已经禁用了 SHA-1,导致 RHEL 6.8 服务器在使用 SSH 或 SCP 连接时无法使用 ssh-rsa 算法进行密钥交换。

      根据 RHEL 9 官网文档 《1.0.2. Crypto-policies, RHEL core cryptographic components, and protocols》 说明:

      在 RHEL 9 中,SHA-1 在默认 (DEFAULT) 系统加密策略中已被限制。除 HMAC 之外,SHA-1 在 TLS、DTLS、SSH、IKEv2、DNSSEC 和 Kerberos 协议中均不再被允许。

      这意味着 RHEL 9 默认拒绝使用 ssh-rsa 作为 HostKey 算法,导致 SSH/SCP 连接失败。

      解决方案:启用 SHA-1 支持

      如果必须使用 SHA-1 进行连接,可以通过 调整 RHEL 9 的加密策略 来解决:

      1. 在 RHEL 9 上执行以下命令,允许 SHA-1:
      update-crypto-policies --set DEFAULT:SHA1

      执行后系统会提示:

      Setting system policy to DEFAULT:SHA1
      Note: System-wide crypto policies are applied on application start-up.
      It is recommended to restart the system for the change of policies
      to fully take place.

      此时再从 RHEL 6.8 服务器进行 sshscp 连接,即可恢复正常。

      下面是执行该命令返回的信息

      Setting system policy to DEFAULT:SHA1
      Note: System-wide crypto policies are applied on application start-up.
      It is recommended to restart the system for the change of policies
      to fully take place.

      此时再从 REHEL6.x ssh 或 scp就正常了

      参考资料

      RHEL9 官网文档(英文)

      Red Hat Product Documentation(中文)

      总结

      问题原因:RHEL 9 默认禁用了 SHA-1,导致 RHEL 6.8 无法使用 ssh-rsa 连接。
      解决方案:在 RHEL 9 上执行 update-crypto-policies --set DEFAULT:SHA1
      最终结果:允许 SHA-1 后,RHEL 6.8 服务器可正常 SSH/SCP 连接 RHEL 9。 🚀

      近期文章:Thordata 住宅代理IP及指纹浏览器配置教程(详细图文)

      Comments

      No comments yet. Why don’t you start the discussion?

      发表评论