如何用 重写以下命令ProxyCommand
?
ssh -l username1 -t jumphost1 \
ssh -l username2 -t jumphost2 \
ssh -l username3 -t jumphost3 \
ssh -l username4 server
Run Code Online (Sandbox Code Playgroud)
这不起作用
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
Run Code Online (Sandbox Code Playgroud)
我知道它nc
与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.
Run Code Online (Sandbox Code Playgroud)
幸运的是,因为7.3
-J
或达到了ProxyJump
我的目的——尽管我仍然必须解决我的密钥设置问题。
ssh -q -J user1@jumphost1,user2@jumphost2,user3@jumphost3 user@server
Run Code Online (Sandbox Code Playgroud)
Jak*_*uje 29
nc
不再推荐该版本。使用-W
最新版本的 OpenSSH 中提供的开关。此外,您不需要将配置复制到其他主机!所有配置都需要在您的主机上完成,并且不会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
Run Code Online (Sandbox Code Playgroud)
然后使用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
Run Code Online (Sandbox Code Playgroud)
你基本上需要从里面去。
Dop*_*oti -1
我已经用两跳完成了此操作,但它应该适用于三跳。最简单的方法是~/.ssh/config
在每个主机上设置该文件。因此,如果您想打开hosta
并访问hostd
viahostb
和 hostc`,您可以这样设置您的配置:
在hosta:~/.ssh/config
:
Host hostd
User username
ProxyCommand ssh hostb nc %h %p 2> /dev/null
Run Code Online (Sandbox Code Playgroud)
在hostb:~/.ssh/config
:
Host hostd
User username
ProxyCommand ssh hostc nc %h %p 2> /dev/null
Run Code Online (Sandbox Code Playgroud)
在hostc:~/.ssh/config
:
Host hostd
User username
ProxyCommand ssh hostd nc %h %p 2> /dev/null
Run Code Online (Sandbox Code Playgroud)
然后,您可以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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23826 次 |
最近记录: |