I can ssh to a remote system of servers via a login server (ssh [email protected]
). From the login server, I can ssh to a particular server (ssh user@supercool
). I cannot access the particular server directly (ssh [email protected]
). How can I run a local rsync to get a directory from this particular server? I cannot rsync from the particular server to my local machine because my local machine does not have a publicly-accessible I.P. address.
1 Answer
So your set up is this:
Local Machine --> Intermediate Server --> Remote Server
If you are able to run the rsync command on the remote server and your local machine is running sshd you can do this:
Log into the intermediate server with the following ssh command
ssh user@<intermediate server> -R 1024:localhost:22
This will create a reverse SSH tunnel. Any SSH connections on the intermediate server on port 1024 will be redirected back to your local machine.
At this point you will be logged into the intermediate server. You then need to extend the tunnel to the remote server. On the intermediate server run:
ssh user@<remote server> -R 1024:localhost:1024
Now, any SSH connection on port 1024 on the remote server will go back to the intermediate server on port 1024 which will then be tunnelled back to your local machine. Phew!
Now we need to wrap this up into rsync. Rsync has a remote shell option (-e) that you can use to specify ssh options. So on the remote server you can run (this is a bit of a guess from past experience, it might need some tweaking):
rysnc -<whatver rsync options you want> -e "ssh -p 1024" <source directory> <local machine user>@localhost
Remember to always run an rsync command with --dry-run first to make sure it's doing what you expect (coupled with various levels of verbosity -v, -vv or -i or -ii depending on the versions of rsync involved.).
-
1@OP, I see you've accepted this answer. Did it work OK for you or does it need some tweaking?– DarrenCommented Apr 4, 2017 at 8:59