3
4
I have 3 computers/servers, let's call them as computer A, computer B and computer C.
- Computer A has access via
ssh
to computer B. - Only computer B has access via
ssh
to computer C. - Computer A doesn't have access to computer C directly.
So, I want to rsync
directories from computer A to computer C, using computer B(since only computer B has access via ssh
to computer C). I want to use rsync
in a simple way, like this:
rsync -options /path_to_local IpComputerC:/path_to_remote
I'm thinking on a ssh
tunnel, but I don't know if I have to make a local port forwarding or a remote port forwarding, or if I have to make two tunnels: one from A to B and other from B to C?
Any suggestions?? I'd be really grateful.
**UPDATE: I dit it!! I created an ssh tunnel with local port forwarding, which means that I used a local port from the machine A to connect with a remote port on the machine C through the machine B. The syntax for the command is:
ssh -f -N -L local_port_machineA:ip_machineC:remoteport_machineC user_machineB@ip_machineB
In my case, remoteport_machineC shoul be port 22, because I want to rsync directories through ssh.
After that, we can execute the rsync command from the machine A, in this way:
rsync -avz -e "ssh -p local_port" /source_directory username_machineC@localhost:/target_directory
That's all. Additionally, you can add more options in the part inside the quotes, such as keys or files, etc.**
My server "C" is a port on localhost on B (that is, there is a reverse tunnel set up from C to B). How can I rsync from A to C? That is, I need to specify different ports on B and C. – CPBL – 2018-10-28T03:56:32.193
Not quite enough information to know exactly how to address your situation. What is being tunneled over ssh (your "reverse tunnel")? Is it ssh? If so, you need only replace the (standard) port with the reverse tunnel endpoint port you specified. – crimson-egret – 2018-10-29T14:31:26.797
Here's my answer to my comment above:
rsync -avzhP -e "ssh -A serverB ssh -p 9222" localfilename localhost:remotefilename
where the tunnel of serverC ends on port 9222 on serverB – CPBL – 2018-10-29T18:13:04.803