I am trying to copy files from a remote server to my local server, however, my remote server first requires me to connect to an intermediate host and then leapfrog onto the actual server from there. I am wondering how would I go about copying files from my remote server to my local machine with the scp command using this leapfrogging technique?

So first I have to connect to intermediate server, then from there I want to connect to my actual server.


With modern versions of ssh this is very easy using the concept of a ProxyJump at least if you have keys set up.

Let us call the 3 machines L, I, and R (for local, intermediate, and remote). Assume to start with that the usernames are all the same.

The command required is then

scp -oProxyJump=I R:remote_file localfile

If the usernames are different then replace I with user@I and R with user@R.

If you are using ssh, the command would be:

ssh -J [user@]I [user@]R 
  • The configuration parameter is named ProxyJump and is invoked when using 'ssh' by the -J [<user>@]<destination> flag. The scp command is slightly differnet, as it makes use of the -oProxyJump=[<user>@]<destination> syntax. Or at least that's what happens (and what the manual pages say) on the two machines where I tested this solution... – Thomas N Nov 19 '19 at 19:52
  • So JumpProxy does not work (gives error: bad configuration option jump proxy). So do I just switch JumpProxy with ProxyJump? – skidjoe Nov 19 '19 at 19:54
  • @skidjoe That would be it... I edited the earlier answer, so hopefully it will be corrected. – Thomas N Nov 19 '19 at 19:59
  • Thanks for your answer, if I'm looking to download a whole file/folder, do I just add -r before the R:remote_file or right after the scp? – skidjoe Nov 19 '19 at 20:06
  • I would use it right after the scp, just to make it more readable in your history (if you ever need to use it again...), so: scp -r -oProxyJump=I R:remote_dir ./local_dir – Thomas N Nov 19 '19 at 23:24

You can do this by editing your ssh configuration to include a proxy. scp uses ssh for remote connections so just editing the ssh config should work. Use your "intermediate server" as the proxy.

Add something like this to your ~/.ssh/config file:

Host target.machine
  User          targetuser
  HostName      target.machine
  ProxyCommand  ssh proxyuser@proxy.machine nc %h %p 2> /dev/null

Then just use scp as if you are connecting directly to the remote server.

To give credit where it's due, I took this from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.