Last active
November 17, 2015 16:23
-
-
Save cuevasclemente/32e51a1b2d56754c9970 to your computer and use it in GitHub Desktop.
SCP Between Remote1 and Remote2 (Remote2 behind proxy)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SCP Protip: Ever needed to copy something between two remote | |
# servers with a proxy (like orbital) in between them? In one step (kinda?)? | |
# Try using this insane `scp` invocation to copy a file from remote host 1 to remote host 2 | |
# which is behind a proxy gateway! | |
scp -v -3 -o "ProxyCommand ssh -A -o StrictHostKeyChecking=no | |
-o UserKnownHostsFile=/dev/null proxy_user@proxyhost nc remotehost2 port_for_remotehost_2" | |
-o "ForwardAgent=yes" -o "StrictHostKeyChecking=no" | |
-o "UserKnownHostsFile=/dev/null" | |
user1@remotehost1:/file/1 | |
user2@remotehost2:/file/1``` | |
# The secret here is the -3 command. When you use the proxy command, | |
# the first thing `scp` does is call the proxy command (in this case | |
# our proxy command is ssh-ing into orbital) (we're invoking these ssh | |
# parameters with the -o flag). If that happens first, you'll be in a | |
# different network, so your remote host 1 | |
# may not necessarily be accessible at the same IP as it would be in your | |
# proxy. The `-3` flag copies the file directly from your remote to the host, | |
# and then does all the other insanity you want it to do before it copies to | |
# your remote (`-3` is a kinda new flag). It's important to set you | |
# `UserKnownHostsFile` to `/dev/null`, lest you upset ssh by having it be concerned | |
# that the host names change between different legs of this `scp` operation. | |
# Same with setting `StrictHostKeyChecking` to `no`. We make sure we forward our | |
# agents as well, just to make sure everyone has everything they need to make sure | |
# that this file is copied successfully and comfortable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment