SSH KexAlgorithms 指定は CLI では機能しますが、ssh_config では機能しません。

SSH KexAlgorithms 指定は CLI では機能しますが、ssh_config では機能しません。

diffie-hellman-group-exchange-sha256デフォルトでは、私のSSHクライアントは鍵交換アルゴリズムの使用を許可しません。ただし、このアルゴリズムを使用する必要がある10.0.0.1のサーバーにアクセスする必要があります。

これはコマンドラインでうまく機能します。

$ ssh -o KexAlgorithms=diffie-hellman-group-exchange-sha256 [email protected]
Password:

ただし、最後に以下を追加しようとすると失敗します/etc/ssh/ssh_config

Host 10.0.0.1
    KexAlgorithms diffie-hellman-group-exchange-sha256

関連出力は次のとおりです。

$ ssh -vvv [email protected]
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug3: kex names ok: [[email protected]]
...
debug1: /etc/ssh/ssh_config line 72: Applying options for 10.0.0.1
debug3: kex names ok: [diffie-hellman-group-exchange-sha256]
...
debug1: Connecting to 10.0.0.1 [10.0.0.1] port 22.
debug1: Connection established.
...
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: [email protected]
...
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256
...
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: mac_setup: setup hmac-ripemd160
debug1: kex: server->client aes256-ctr hmac-ripemd160 none
debug2: mac_setup: setup hmac-ripemd160
debug1: kex: client->server aes256-ctr hmac-ripemd160 none
Unable to negotiate a key exchange method

これについて私を混乱させることは、SSHが関連する行をはっきりと読んで/etc/ssh/ssh_configそれに満足しているようです。ただし、[email protected]サーバーとの鍵交換をネゴシエートする代わりにを使用しようとしましたが、diffie-hellman-group-exchange-sha256当然失敗します。

なぜこれが起こり、どのように解決できますか?

ベストアンサー1

一見すると、OpenSSHオプションが少し奇妙に見えるかもしれません。ただし、マニュアルページにはssh_configこれについて詳しく説明しています。

各パラメータに対して最初に取得された値が使用されます。。構成ファイルには、「ホスト」仕様で区切られたセクションが含まれています。このセクションは、仕様で提供されているパターンの1つと一致するホストにのみ適用されます。一致するホスト名は通常、コマンドラインで指定されたホスト名です(例外についてはCanonicalizeHostnameオプションを参照)。

必要なことを達成するには、次のように構成を再作成できます(スターマッチングは最後のものでなければなり*ません)。

Host 10.0.0.1
    KexAlgorithms diffie-hellman-group-exchange-sha256
#[...]
Host *
    KexAlgorithms [email protected]

私の答えは重複しています。

また、同じマニュアルページでコマンドラインオプションが機能する理由についても説明しますssh_config

  1. コマンドラインオプション
  2. ユーザー設定ファイル(~/.ssh/config)
  3. システム全体の構成ファイル(/etc/ssh/ssh_config)

おすすめ記事