web-dev-qa-db-ja.com

SSH構成ProxyCommandは公開鍵を要求します

ゲートウェイを介してEC2インスタンスに接続しようとしています。

ゲートウェイに接続した場合

local> ssh gateway

その後、パスワードなしでEC2に接続できます

gateway> ssh ec2  # works

ただし、プロキシを介して接続しようとすると、IDファイルが必要になるようです。

Host gateway
    HostName <gateway>

Host ec2
    HostName ec2-<ec2>.compute.amazonaws.com
    ProxyCommand ssh gateway -W %h:%p


local> ssh ec2
Permission denied (publickey).

ProxyCommandは基本的に私をゲートウェイにログインさせてから、最終的な宛先にログインさせていると思いました。もしそうなら、ゲートウェイが公開鍵を必要としないように設定されているときに、なぜ公開鍵を要求するのでしょうか?ゲートウェイにSSH接続してからec2にSSH接続するのと同じ方法でec2インスタンスに接続するにはどうすればよいですか?

編集:rsyncは正常に機能します(キーファイルを要求しません)

rsync -pthrvz  --rsync-path=/usr/bin/rsync --rsh='ssh gateway ssh' . ec2:/path

ssh -v gateway> ssh ec2からの出力

gateway> ssh -v ec2
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to ec2 port 22.
debug1: Connection established.
debug1: identity file <snip> type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'ec2' is known and matches the RSA Host key.
debug1: Found key in ~/.ssh/known_hosts:63
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: ~/.ssh/identity
debug1: Offering public key: ~/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.

プロキシ経由で接続しようとしたときのssh-v出力

local$ ssh -v ec2 
OpenSSH_6.7p1 Ubuntu-5ubuntu1.3, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/matt/.ssh/config
debug1: /home/matt/.ssh/config line 9: Applying options for ec2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Hostname has changed; re-reading configuration
debug1: Reading configuration data /home/matt/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Executing proxy command: exec ssh gateway -W ec2:22
debug1: permanently_drop_suid: 1000
debug1: identity file /home/matt/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/matt/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/matt/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/matt/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/matt/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/matt/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/matt/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/matt/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Ubuntu-5ubuntu1.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server Host key: ECDSA 73:<snip>:0c
debug1: Host 'ec2.compute.amazonaws.com' is known and matches the ECDSA Host key.
debug1: Found key in /home/matt/.ssh/known_hosts:11
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/matt/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/matt/.ssh/id_dsa
debug1: Trying private key: /home/matt/.ssh/id_ecdsa
debug1: Trying private key: /home/matt/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

問題は、ゲートウェイマシンからキーを取得するのではなく、自分のマシンでキーを見つけようとしていることのようです。

3
Matt McCormick

ProxyCommandは、思ったとおりに機能しません。指定されたコマンドは、ゲートウェイマシンでは実行されません。むしろ、接続マシン上で実行されます。

したがって、実行の流れは次のとおりです。

  1. ProxyCommand「sshgateway-W%h:%p」は「ローカル」マシンで実行されます。これにより、ローカルボックスのRSA IDを使用して、ゲートウェイへのSSHセッションが確立されます。 -Wフラグは、stdinとstdoutが最終的な宛先へのゲートウェイ上のTCPセッション発信元に接続されることを指定します。

  2. プロキシセッションが確立されると、ローカルボックスのsshは再びそのセッションを使用して、ローカル資格情報を使用してリモートSSHサーバーへの認証を行います。

少し紛らわしいですが、ProxyCommandは、ローカルSSHクライアントと最終的な宛先であるSSHサーバーの間に「パイプ」を設定するだけだと考えてください。次に、そのダムパイプは、ローカルSSHクライアントが最終的な宛先のSSHサービスと通信するために使用されます。

したがって、重要なのは、ローカルボックスで実行されているSSHのインスタンスがtwoあることです。そのうちの1つはProxyCommandであり、もう1つは確立する実際のSSH接続です。ローカルボックスの「psaux」の出力を確認することで、それを確認できるはずです。

それは、認証のためにゲートウェイではなく、ローカルボックスでキーマテリアルを使用しようとしている理由を説明します。 :-)

Rsyncが機能する理由は、実際には--rshコマンドとして「sshgateway ssh」を実行しているためです。これは、実際にはローカルボックスでsshを実行してゲートウェイに接続し、次にリモートボックスでもう一度実行します。次に、リモートキーマテリアルを使用します。

お役に立てれば。

10