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
  • 1
  • 2
    Search this site for ssh ProxyCommand. Setup a ssh_config for that host. Rsync will use the config. – Zoredache Jan 06 '17 at 18:12
  • I've tried that it didn't work. I'm already using a config for the hosts. – turen Jan 06 '17 at 18:33
  • 1
    Then it would be helpful if you add your `~/.ssh/config` to your question. – Thomas Jan 06 '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 06 '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 06 '17 at 18:55
  • Thanks Rik thats' what I'm looking for. That doesn't work but in the right direction. That command tries to source the file from A. I want rsync -e 'ssh -A -t HostB "ssh user@localhost -pXXXXX" ' SOURCE=hostC TARGET=HostA – turen Jan 06 '17 at 21:05

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
alexander.polomodov
  • 1,068
  • 3
  • 10
  • 14
  • 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 06: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](https://serverfault.com/a/934660/214507) for a slightly simpler scenario. Perhaps you can expand on that. – kasperd Oct 22 '18 at 15:06
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.

Dmitriy Kupch
  • 471
  • 2
  • 6