Friday, November 15, 2013

rsync With Host in the Middle

I have clients that have configured their firewalls so that I must use my office Internet address when connecting to their servers.  This is inconvenient for me when traveling, but I understand their concerns.

This means I must connect to their system via my office server.  When using ssh, it's typically two commands:

ssh -A -X myoffice-computer
ssh -X the-client-computer # issued from myoffice-computer session
However, with rsync you can't break up the commands, or can you?  The -e option allows you to feed arguments to the underlying ssh transport. So:
rsync -a -e 'ssh -A myoffice-computer ssh' \
localfile client-computer:/path/dir
The file transfer can be in either direction.  rsync splices the specified remote hostname into the ssh commands.  This will work for longer chains of ssh connections.  Just follow the pattern:
-e 'ssh -A host1 ssh -A host2 ssh'
I've been using the ssh -A option in my examples.  From the man page:
-A      Enables forwarding of the authentication agent connection.
This can also be specified on a per-host basis in a configuration file.
You may need a different approach depending upon how you've configured authentication and distributed your keys among the different computers.