I have seen plenty of examples for scp through an intermediate server to a second-hop server via ProxyCommand operator such that:

A:/infile.txt -> B -> C:/outfile.txt

Which looks something like the following from A:

scp -o 'ProxyCommand ssh userB@hostB nc %h %p' infile.txt userC@hostC:"~/outfile.txt"

My question, is how to scp through two intermediate servers to a third-hop server such that:

A:/infile.txt -> B -> C -> D:/outfile.txt

I'm looking for a way to do this using one-liner similar to the second-hop example provided above ... but all answers and means are valid if that's not possible.

What I'm trying to do is not the same as SCP through multiple hosts or variants thereof, which uses /etc/ssh/ssh_config file for setting up aliases. That's not what I'm wanting to do, I'm looking for a one-liner. I've also not seen any examples of two or more proxy hosts in between origin and destination, so I believe the question is quite valid.

  • @Jakuje, however I will give you credit... that does work, it's just not what I'm looking for.
    – SYANiDE
    Commented Dec 3, 2016 at 18:38

1 Answer 1


The new openssh 7.3 provides the switch -J which allows you to create your desired one-liner:

scp -oProxyJump=userB@hostB,userC@hostC infile.txt userD@hostD:"~/outfile.txt"

From manual page:


Specifies one or more jump proxies as [user@]host[:port]. Multiple proxies may be separated by comma characters and will be visited sequentially. Setting this option will cause ssh(1) to connect to the target host by first making a ssh(1) connection to the specified ProxyJump host and then establishing a TCP forwarding to the ultimate target from there.

  • Thanks! I saw this one earlier today on en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts. I'm using OpenSSH 7.2p1 and I'm weary of updating to 7.3 out of fear it'll break my Kali install, and I'm studying for the OSCP... so it's important I don't risk breaking the install until at least after I take the exam. Do you by any chance know of any other way to do it, using one-liner? I'm looking for a way prior to OpenSSH 7.3 if possible.
    – SYANiDE
    Commented Dec 3, 2016 at 18:49
  • 1
    I was trying similar way with older openssh in related question, but it is big mess. I didn't try it, but conceptually it should work
    – Jakuje
    Commented Dec 3, 2016 at 18:51
  • Oh, I see what you mean... quite messy indeed. I was hoping for something similar to just specifying either individual -oProxyCommand ' ' switches or nested; I see this example from the link is the nested version, and it's dirty dirty. I think future-wise, your answer is preferred, so marking as solved. Thank you!
    – SYANiDE
    Commented Dec 3, 2016 at 18:56
  • 1
    That is one of the reasons why the ProxyJump option was implemented in OpenSSH. Unless enough people starts using stuff, it is hard to get all the use cases and possible troubles. ProxyCommand is good for a lot of stuff in ssh_config, but not for ad-hoc forwarding and going through more jumps
    – Jakuje
    Commented Dec 3, 2016 at 19:01

Not the answer you're looking for? Browse other questions tagged .