Search code examples
sshrsyncfile-transfer

Transferring files between two remote hosts, having authorized keys locally?


I have access to two remote systems via SSH authorized keys and I want to transfer files directly between them. Ideally with rsync. Password authentication is disabled on both remote systems, using my local SSH key is the only way I can log in.

I wonder if there is a way to initiate an rsync-transfer from one remote host to the other one using SSH auth forwarding?

I catch myself using workarounds every so often to achieve this:

  • Adding the public key from public host A to public host B temporarily and do a direct rsync transfer.
  • Mounting both remote hosts via sshfs or using two Cyberduck windows. This slows things down due to the bottleneck of the local connection but it works for small amount of data.
  • Using Magic Wormhole to do the transfer

All workarounds mentioned above are somehow fiddly and / or slow.

What is the best option?


Solution

  • I figured out that this is pretty easy to achieve using ssh-agent.

    Just for reference:

    local> eval $(ssh-agent) #Start ssh-agent
    local> ssh-add <private_key> #for example .ssh/id_rsa
    local> ssh -A public-host-a #-A enables ssh agent forwarding
    public-host-a> rsync -av /data public-host-b:/data
    

    Using ssh agent forwarding, it makes the remote system behave as if the private key from the local system has been copied over to the target system. It is also possible to checkout private git repositories directly from a remote system which seems quite handy to me.