跳到主要内容
ecdsa.com
OpenSSH client (8.8+) connecting to a server that only offers legacy host key algorithmsSSH

错误信息

Unable to negotiate with 127.0.0.1 port 22: no matching host key type found. Their offer: ssh-rsa

也可能输出为

  • no matching host key type found. Their offer: ssh-rsa,ssh-dss
  • Unable to negotiate with 127.0.0.1 port 22: no matching key exchange method found. Their offer: diffie-hellman-group14-sha1

主机和端口以及服务器提供的算法会有所不同。密钥交换的提示为“no matching key exchange method found”,加密算法的提示为“no matching cipher found”。

含义

客户端和服务器没有共同的主机密钥算法,因此连接在算法协商阶段就停止了——早于主机验证和登录。“Their offer”列出的是服务器提出的算法。OpenSSH 8.8 及以上版本默认禁用 `ssh-rsa`(使用 SHA-1 的 RSA)和 `ssh-dss`(DSA);只提供这些算法的服务器通常是老旧的专用设备、路由器、NAS 设备或未打补丁的系统。密钥交换方面的变体(“no matching key exchange method found”)形式相同,解决办法也相同。

原因

修复方法

  1. 1.

    只对该主机允许旧算法

    用 `Host` 块把 SHA-1 限制在需要它的设备上。切勿把 `+ssh-rsa` 放在 `Host *` 下。

    text
    # ~/.ssh/config - re-enable the legacy algorithm for that one device only
    Host old-switch.lan
      HostKeyAlgorithms +ssh-rsa
      PubkeyAcceptedAlgorithms +ssh-rsa
  2. 2.

    为服务器配置现代主机密钥

    更新设备的固件或 OpenSSH,并生成 Ed25519/ECDSA 主机密钥,就不再需要例外配置。

    bash
    # On the server: generate modern host keys and let sshd offer them
    ssh-keygen -A                                   # creates missing ed25519/ecdsa host keys
    sshd -T | grep -E "^hostkeyalgorithms|^hostkey "  # what the server will offer

相关错误

浏览完整的签名错误库