Been searching for awhile on this and haven't found a solution.

Machine C has a persistent reverse tunnel to machine B. I.e machine B can connect back to machine C thru the reverse tunnel. I can rsync files from C to B and then retrieve them with A to B.

How would one rsync from A to C and retrieve files.

I can can currently connect directly to C from A with ssh -A -t HostB "ssh user@localhost -pXXXXX"


  • 2
    Search this site for ssh ProxyCommand. Setup a ssh_config for that host. Rsync will use the config. – Zoredache Jan 6 '17 at 18:12
  • I've tried that it didn't work. I'm already using a config for the hosts. – turen Jan 6 '17 at 18:33
  • 1
    Then it would be helpful if you add your ~/.ssh/config to your question. – Thomas Jan 6 '17 at 18:39
  • Didn't work how? Add more details to your question. Use verbose mode. Give us something to work with here. It should work. If it isn't, it is either because you have something setup wrong, or something unusual is being done in your environment. – Zoredache Jan 6 '17 at 18:40
  • 1
    Silly thought. Have you attempted anything on the order of (( rsync -e 'ssh -A -t HostB "ssh user@localhost -pXXXXX" ' SOURCE TARGET )) ??? – Rik Schneider Jan 6 '17 at 18:55

I was struggling with exactly the same problem. The solution is to use ssh port forward on the machine initiating to machine B, and ssh reverse port on the machine that receives. In the following examples--

deh is user name
export BIP= (B's IP address)
22    (A's ssh listening port)
41572 (B's ssh listening port)
22221 (local port on B from reverse ssh of A)
22223 (local port on B from reverse ssh of C)
22    (C's ssh listening port)

Machines A and C have persistent reverse port forward connections to B. e.g. setup with the following--

ssh -R 22221:localhost:22 deh@$BIP -p 41572
ssh -R 22223:localhost:22 deh@$BIP -p 41572

If machine A wants to access machine C, machine A sets up a ssh forward port connection to the reverse port that C has set on B, e.g.--

ssh -L 22223:localhost:22223 deh@$BIP -p 41572

With this connection, A can then initiate a connections to C.

On A get a terminal on C in one step--

ssh -p 22223 deh@localhost 

On A transfer a directory with files to C, e.g.--

rsync -ruav -e 'ssh -p 22223' /home/deh/datafiles deh@localhost:/home/deh

If wants C to access A, C sets up a forward port connection to B using the reverse port A set on B, e.g.--

ssh -L 22221:localhost:22221 deh@$BIP -p 41572

C then can ssh to A in one step such ssh, rsync, etc.

ssh -p 22221 deh@localhost
  • This sounds way more complicated than it need to be. Adding a section to .ssh/config using ProxyCommand should be sufficient. – kasperd Oct 20 '18 at 6:34
  • An example of ProxyCommand would be useful. I've tried several versions without success. It looks like all the ProxyCommand would do is place the forward port connection step into the ssh config file; the steps to setup the reverse connections are still needed. – user3304253 Oct 22 '18 at 15:02
  • Here is one for a slightly simpler scenario. Perhaps you can expand on that. – kasperd Oct 22 '18 at 15:06

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.