How to transfer a file between two remote servers using scp from a third, local machine?

Alan picture Alan · Mar 3, 2015 · Viewed 41.1k times · Source

I'm trying to copy a file from one remote server to another remote server from my local machine. Here's what I'm trying to do

localA $ scp userB@remoteB:/path/to/file userC@remoteC:/path

The problem is that I need to pass two passwords for both userB and userC on the remote machines.

According to Garron the above should work, but I got permission denied.

Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive).
lost connection

Any suggestions?

Answer

RubenCaro picture RubenCaro · May 16, 2016

If you can ssh to both remote servers from your local (local -> remote1 & local -> remote2), then you could try:

ssh -A -t user1@remote1 scp srcpath user2@remote2:destpath

This will transfer straight from remote1 to remote2 using your local credentials all the way.

If you do not want to be asked for passwords, then you should set up the authorized_keys file on remotes.