0

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

turen
  • 1

2 Answers2

1

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
0

I believe my solution would be relevant as well.

Synopsis: Copy a file/files between two servers that are not connected directly

Variables: Machine A cannot directly connect to C and vice-versa. Machine B has access to A and C.

Diagram: A ---->B_SSH-TUNNEL_B---> C

  • A - Source machine
  • B - Local machine
  • C - Destination machine

Solution:

# Map serverB's 5001 port > serverC:22
username@serverB:~$ ssh -L 5001:localhost:22 serverC

Create a reverse proxy which would link remote serverA:5000 to serverB 5001

username@serverB:~$ ssh -R 5000:localhost:5001 serverA

From remote host serverA execute the following command to push file to serverC:

username@serverA:~$ rsync -azvh -e 'ssh -p 5000' /home/username/file1 username@localhost:/home/username/

To avoid password requests we could forward SSH agent by passing -A option to the ssh command

-A Enables forwarding of the authentication agent connection.