エラーメッセージ
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」)も同じ形で、対処法も同じです。
発生する理由
古い組み込み SSH サーバー
よくあるスイッチ、ファイアウォール、プリンター、ストレージ機器では、RSA/SHA-1 のホスト鍵しか持たない dropbear や古いバージョンの OpenSSH が動いていることがよくあります。
最新のホスト鍵を持たないサーバー
ときどきかなり前にインストールされたシステムには、RSA のホスト鍵しかなく、sshd も古すぎて `rsa-sha2-256/512` で署名できない場合があります。
制限の厳しいクライアント設定
ときどき`~/.ssh/config` や `/etc/ssh/ssh_config.d` にある、Ed25519 だけを列挙した `HostKeyAlgorithms` の行は、ECDSA または RSA の鍵しか持たないサーバーを拒否します。
修正方法
- 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.
サーバーに最新のホスト鍵を用意する
機器のファームウェアや 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