如何使用第二个远程主机 scp [英] How to scp with a second remote host

查看:68
本文介绍了如何使用第二个远程主机 scp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法通过 remote1 主机直接从我的本地计算机从 remote2 主机 SCP 文件.

I wonder if there is a way for me to SCP the file from remote2 host directly from my local machine by going through a remote1 host.

网络只允许从 remote1 主机连接到 remote2 主机.此外,remote1 主机和 remote2 主机都无法 scp 到我的本地机器.

The networks only allow connections to remote2 host from remote1 host. Also, neither remote1 host nor remote2 host can scp to my local machine.

有没有类似的东西:

scp user1@remote1:user2@remote2:file .

第一个窗口:ssh remote1,然后是scp remot2:file ..

First window: ssh remote1, then scp remot2:file ..

第二个 shell:scp remote1:file .

第一个窗口:rm文件;退出

我可以写一个脚本来完成所有这些步骤,但如果有直接的方法,我宁愿使用它.

I could write a script to do all these steps, but if there is a direct way, I would rather use it.

谢谢.

我正在考虑诸如打开 SSH 隧道之类的事情,但我对将什么值放在哪里感到困惑.

I am thinking something like opening SSH tunnels but i'm confused on what value to put where.

目前,为了访问 remote1,我在本地机器上的 $HOME/.ssh/config 中有以下内容.

At the moment, to access remote1, i have the following in $HOME/.ssh/config on my local machine.

Host remote1
   User     user1
   Hostname localhost
   Port     45678

一旦在 remote1 上,访问 remote2,它是标准的本地 DNS 和端口 22.我应该在 remote1 和/或localhost 上的变化?

Once on remote1, to access remote2, it's the standard local DNS and port 22. What should I put on remote1 and/or change on localhost?

推荐答案

我不知道有什么方法可以在一个命令中直接复制文件,但是如果您可以承认在后台运行 SSH 实例以保持端口转发隧道打开,然后您可以在一个命令中复制文件.

I don't know of any way to copy the file directly in one single command, but if you can concede to running an SSH instance in the background to just keep a port forwarding tunnel open, then you could copy the file in one command.

像这样:

# First, open the tunnel
ssh -L 1234:remote2:22 -p 45678 user1@remote1
# Then, use the tunnel to copy the file directly from remote2
scp -P 1234 user2@localhost:file .

请注意,您在实际的 scp 命令中以 user2@localhost 身份连接,因为第一个 ssh 在 localhost 上的端口 1234 上实例正在监听到 remote2 的转发连接.另请注意,您不需要为每个后续文件副本运行第一个命令;你可以简单地让它运行.

Note that you connect as user2@localhost in the actual scp command, because it is on port 1234 on localhost that the first ssh instance is listening to forward connections to remote2. Note also that you don't need to run the first command for every subsequent file copy; you can simply leave it running.

这篇关于如何使用第二个远程主机 scp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆