Ssh – Rsync from A to C thru reverse tunnel on B

rsyncsshtunnel

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"

Thanks

Best Answer

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=47.208.123.123 (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