openssh クライアント構成のオプションのオーバーライド

openssh クライアント構成のオプションのオーバーライド

SSH接続を保護したいので、使用されるアルゴリズムセットを制限するためにいくつかのグローバル暗号スイートのオプションを設定しました。しかし、最近、これらのアルゴリズムのいくつかをサポートしていないサーバーに会いました。したがって、クライアント(マイシステム)構成で特定のホストレコードに対して使用されなくなったアルゴリズムを選択的に有効にする必要があります。

オプションのオーバーライドが期待どおりに機能しないことがわかりました。 Githubで動作しない最小限の例を見てみましょう。

HostKeyAlgorithms [email protected],ssh-ed25519,[email protected],ecdsa-sha2-nistp521,ecdsa-sha2-nistp256

Host github
    HostKeyAlgorithms ssh-rsa
    Hostname        github.com
    Port            22
    User            git
    PubkeyAuthentication yes
    IdentityFile    ~/.ssh/some-filename-here

これにより、次のエラーが発生します(HostKeyAlgorithmsまったくオーバーライドされません)。

debug1: /home/username/.ssh/config line 14: Applying options for github
<...>
debug2: kex_parse_kexinit: [email protected],ssh-ed25519,[email protected],ecdsa-sha2-nistp521,ecdsa-sha2-nistp256
<...>
Unable to negotiate with 192.30.252.130: no matching host key type found. Their offer: ssh-dss,ssh-rsa

PubkeyAuthentication no同様に、ホスト構成が上書きされたグローバルオプションでは機能しません。

また、match次のいずれも役に立ちません。

match host github
    HostKeyAlgorithms ssh-rsa

それでは、これらのオプションを選択的にオーバーライドする方法はありますか?

注:私はGentooでopenssh-7.1_p2-r1を使用しています。

ベストアンサー1

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

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

必要なことを達成するために、次のように構成を上書きできます。

Host github
    HostKeyAlgorithms ssh-rsa
    Hostname        github.com
    Port            22
    User            git
    PubkeyAuthentication yes
    IdentityFile    ~/.ssh/some-filename-here
Host *
    HostKeyAlgorithms [email protected],ssh-ed25519,[email protected],ecdsa-sha2-nistp521,ecdsa-sha2-nistp256

おすすめ記事