複数のホップとプロンプト認証のためのProxyCommandの使用


17

で次のコマンドを書き換えるにはどうすればよいProxyCommandですか?

ssh -l username1 -t jumphost1 \
ssh -l username2 -t jumphost2 \
ssh -l username3 -t jumphost3 \
ssh -l username4    server

これは機能しません

ssh -o ProxyCommand="\
ssh -l username1 -t jumphost1  \
ssh -l username2 -t jumphost2  \
ssh -l username3 -t jumphost3" \
    -l username4    server

username1@jumphost1's password:
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
ssh_exchange_identification: Connection closed by remote host

私はでの使用を認識していますがnc、3 +ホップで使用する方法を探しており、でこのオプションを使用していますscp。私はssh_configマニュアルページをチェックしましたが、少なくとも私にとっては、情報は非常に少ないです。

編集

私は下に提案されているようProxyCommandに別のネストを使用しようとしましたProxyCommandが、私は常に次の行に沿って何かを得ます

debug3: ssh_init_stdio_forwarding: 192.17.2.2:2222
debug1: channel_connect_stdio_fwd 192.17.2.2:2222
debug1: channel 0: new [stdio-forward]
debug2: fd 4 setting O_NONBLOCK
debug2: fd 5 setting O_NONBLOCK
debug1: getpeername failed: Bad file descriptor
debug3: send packet: type 90
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug1: Requesting no-more-sessions@openssh.com
debug3: send packet: type 80
debug1: Entering interactive session.

幸いなことに、以来、7.3 -JまたはProxyJump私の目的を果たす-私はまだ私のキーの設定を回避するには持っているものの。

ssh -q -J user1@jumphost1,user2@jumphost2,user3@jumphost3 user@server

回答:


25

このncバージョンは推奨されなくなりました。-WOpenSSHの最近のバージョンで提供されているスイッチを使用します。また、設定を他のホストにコピーする必要はありません!すべての設定はホストで実行する必要がありscp、いかなる方法でも干渉しません。以下を使用してファイル~/.ssh/configを作成するだけです。

Host jumphost1
  User username1
Host jumphost2
  User username2
  ProxyCommand ssh -W %h:%p jumphost1
Host jumphost3
  User username3
  ProxyCommand ssh -W %h:%p jumphost2
Host server
  User username4
  ProxyCommand ssh -W %h:%p jumphost3

次に、をssh server使用して接続するか、を使用しますscp file server:path/。onelinerを主張する場合(またはProxyCommandネストについて何を意味するかわからない場合)、既に指摘したように、それはエスケープの地獄です:

ssh -oProxyCommand= \
  'ssh -W %h:%p -oProxyCommand= \
    \'ssh -W %h:%p -oProxyCommand= \
      \\\'ssh -W %h:%p username1@jumphost1\\\' \
    username2@jumphost2\' \
  username3@jumphost3' \
username4@server

基本的には内側から行く必要があります。


ありがとう。ワンライナーを試してみましたが、うまくいきませんでした。逃げるだけなのかどうかはわかりません。再確認してください。また、ネストが必要で、チェーンが機能しない理由を説明できますか?
1.61803

1
さて、「機能しない!」平均?scpSCPはSCP制御メッセージを予期しているため、連鎖は機能しますが、SSH制御メッセージを取得して失敗します。一方、ProxyCommand透過的に行うため、最も外側ssh(またはscp)が相手から直接メッセージを取得します。
-Jakuje

> 行の継続を中断するのを待っているプロンプトが表示されます。つまり、コマンドは実行されません。
1.61803

1
@TrevorBoydSmithすべてのプロキシホストに外部プログラム(nc)をインストールする必要があるため。-Wを使用したIOリダイレクトにはこれは必要ありません。唯一の要件は、opensshクライアントをコンピューターにインストールすることです。
Jakuje

2
ダブル@RomanDodin %動作するはずです:%%hあなたのケースで
Jakuje

-1

これを2ホップで行いましたが、3ホップで動作するはずです。最も簡単な方法は~/.ssh/config、各ホストにファイルを設定することです。そのhostaため、hostd経由hostbしてhostc`にアクセスする場合は、次のように構成を設定できます。

hosta:~/.ssh/config

Host hostd
    User username
    ProxyCommand ssh hostb nc %h %p 2> /dev/null

hostb:~/.ssh/config

Host hostd
    User username
    ProxyCommand ssh hostc nc %h %p 2> /dev/null

hostc:~/.ssh/config

Host hostd
    User username
    ProxyCommand ssh hostd nc %h %p 2> /dev/null

その後ssh hostd、チェーン内のホストのいずれかで、あなたはあなたの道を作るでしょうhostd

プロキシにnetcatを使用しても、に干渉しませんscp

何らかの理由で本当にローカル~/.ssh/configファイルを使用したくない場合は、次の場所で実行できますhosta

ssh -oProxyCommand='ssh -oProxyCommand=\'ssh -o ProxyCommand=\\\'ssh username@hostd nc %h %p 2>/dev/null\\\' username@hostc nc %h %p 2> /dev/null' username@hostb nc %h %p 2> /dev/null' username@hostd

私が言ったように、私はncの使用を知っています。ProxyCommandオプションとして投稿したコマンドを実際に書き換えることはできますか?
1.61803

あなたは「あなたはその使用を知っているが、使用したい」と言いますscp。干渉しませんscp。しかし、すぐに編集としてコミカルに長いコマンドを提供します。
-DopeGhoti

ありがとう。ProxyCommandネストに焦点を当てて答えを書き直せますか?私の投稿を再読すると、それが要点であることがわかります。私は、あなたのようにネストする代わりに、すべての中間ノードを連鎖させることができると思いましたProxyCommand。どういうわけかそれが可能かどうかはまだ疑問です。
1.61803

それが実際に行われていることです。入れ子になった(そしてますますエスケープされた)引用符があるため、in-situ構成よりも読みにくくなります。すべてのProxyCommandディレクティブを一緒にチェーン内の次のホストに運ぶため、そのようにする必要があります。
-DopeGhoti

これは間違っています。構成はローカルコンピューターのみにあり、提案しようとしている途中でホスト間で分散されません。
-Jakuje
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.