Ssh – rsync over ssh tunnel

rsyncsshssh-tunneling

----------         /|                      /|             ------------
|  Home  |        | |                     | |             |    Work   |
|        |--------| |---------------------| |-------------|           |
|ssh-serv|   Firewall:Port-22=open     Firewall           |           |
----------        | |                     | |             ------------
                  |/                      |/

Here is the scenario for the above picture:

A worker has access at his Work machine and has also set up a Home ssh server.
The worker wants to access his Work machine from his PC@Home but the policy of the company restricts access via the Firewall@Work, but allows him to connect via reverse ssh tunnel. So the worker gives the following command from his workstation@Work :

ssh -fN -R 19999:localhost:22 Home-user@Home

Now from his PC@Home he is able to give the following command and connect to the ssh server of his workstation@Work:

ssh -v Work-user@localhost -p 19999

Is it possible for the worker to use rsync to copy a directory from his PC@Home to his workstation@Work using the existing tunnel?

Best Answer

I think the feature you're looking for is called connection sharing. Add this to your $HOME/.ssh/config file:

ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r

excerpt #1 from SSH Can Do That? Productivity Tips for Working with Remote Servers

Fortunately OpenSSH has a feature which makes it much snappier to get another terminal on a server you’re already connected to: connection sharing.

excerpt #2

Shared connections aren’t just a boon with multiple terminal windows; they also make copying files to and from remote servers a breeze. If you SSH to a server and then use the scp command to copy a file to it, scp will make use of your existing SSH connection ‒ ... Connections are also shared with rsync, git, and any other command which uses SSH for connection.

References