本文へスキップ
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」には、サーバーが提案したものが列挙されます。`ssh-rsa`(SHA-1 を使う RSA)と `ssh-dss`(DSA)は、OpenSSH 8.8 以降ではデフォルトで無効です。それ以外を何も提示しないサーバーは、たいてい古いアプライアンス、ルーター、NAS、またはパッチが適用されていないシステムです。鍵交換版のエラー(「no matching key exchange method found」)も同じ形で、対処法も同じです。

発生する理由

修正方法

  1. 1.

    そのホストに限ってレガシーなアルゴリズムを許可する

    `Host` ブロックを使えば、SHA-1 の使用を、それを必要とする機器だけに限定できます。`Host *` の下に `+ssh-rsa` を書いてはいけません。

    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

関連するエラー

署名エラーデータベースをすべて見る