LoginSignup
6
3

More than 1 year has passed since last update.

Unable to negotiate with : no matching host key type found. Their offer: ssh-rsa,ssh-dss

Last updated at Posted at 2022-02-02

事象 : 踏み台の先にあるEC2へssh接続しようとしたら怒られた

  • 環境
    • OpenSSH_8.8p1, OpenSSL 1.1.1m 14 Dec 2021
    • 踏み台OS : Amazon Linux release 2 (Karoo)
    • 接続先OS : CentOS release 6.7 (Final)
$ ssh old-host
Enter passphrase for key '/path/to/fumidai.pem': 
Unable to negotiate with UNKNOWN port 65535: no matching host key type found. Their offer: ssh-rsa,ssh-dss
~/.ssh/config
# 踏み台
Host fumidai
    HostName xx.1xx.1xx.1xx
    User ponsuke
    IdentityFile /path/to/fumidai.pem

# 接続先
Host old-host
    HostName 10.0.x.xx
    User tarou
    IdentityFile /path/to/id_rsa
    ProxyCommand ssh fumidai -W %h:%p

原因 : OpenSSH8.8からSHA-1のRSA鍵は無効になったから

This release disables RSA signatures using the SHA-1 hash algorithm by default.
https://www.openssh.com/txt/release-8.8

(ざっくり訳)本リリースでは、SHA-1ハッシュアルゴリズムを使用したRSA署名をデフォルトで無効化します。

今回は踏み台の鍵でパスフレーズを聞かれた後エラーになったので、たぶん接続先のホストに使っている鍵が古いようだ。
秘密鍵でアルゴリズムを確認できなかったので、ホストへ出かけて公開鍵でアルゴリズムを確認してみた。

# 踏み台はSHA-2だった
$ ssh-keygen -l -f authorized_keys
2048 SHA256:... (RSA)
# 接続先はSHA-1...
$ ssh-keygen -l -f .ssh/authorized_keys 
3072 xx:...:xx .ssh/authorized_keys (RSA)

同じようなことがOpenSSH7.0ではDSA鍵であったらしい。

OpenSSH 7.0 and greater similarly disable the ssh-dss (DSA) fumidai key algorithm.
OpenSSH: Legacy Options

(ざっくり訳)OpenSSH7.0以降では、ssh-dss (DSA) 公開鍵アルゴリズムが無効にされています。

対応 : .ssh/configに設定を追加する

ホストの公開鍵の種類を古い鍵も使えるように追加をします。

Host old-host
    # ...省略...
    HostkeyAlgorithms +ssh-rsa

.ssh/configの設定を変えたらssh-keygen -Rで、古い情報をknown_hostsから消します。
これを忘れるとWARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!というエラーになるので注意してください。

# 古い情報をknown_hostsから消してあげる
$ ssh-keygen -R 10.0.x.xx
# Host 10.0.x.xx found: line 34
/c/Users/ponsuke/.ssh/known_hosts updated.
Original contents retained as /c/Users/ponsuke/.ssh/known_hosts.old

# もう一度接続する
$ ssh old-host
Enter passphrase for key '/path/to/fumidai.pem': 
The authenticity of host '10.0.x.xx (<no hostip for proxy command>)' can't be established.
RSA key fingerprint is SHA256:xxxxxx.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.x.xx' (RSA) to the list of known hosts.
Enter passphrase for key '/path/to/id_rsa': 
sign_and_send_pubkey: no mutual signature supported
ponsuke@10.0.x.xx's password:
Last login: Thu Feb 17 14:32:13 2022 from xx.1xx.1xx.1xx
[ponsuke@ip-10-0-x-xx ~]$

他の対応

やっていないけど将来のためにメモ、いや、早く鍵交換しなきゃ。

  1. 新しいアルゴリズムで鍵を作り直す
    1. 接続先がEC2だと使えないものあるので注意です
      1. Amazon EC2 が使用するキーは、 ED25519もしくは2048-bit SSH-2 RSA キーです。
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3