What arguments would I use for the scp command on a server to server copy if the two servers need different ssh keys? I know how to scp files from a server to a server without having data flow on the PC (the one from which I issued the scp command).

Based on this tutorial, my starting command looks something like this:

scp -r miguel@ miguel@
  • I would question your statement that scping from one remote host to another using a third machine to issue the command doesn't transfer data over the wire to your local PC to and from the remotes. Are you sure about that or is this just a convenience command for what gets run as a two step process? – Caleb Jun 26 '11 at 21:17

Use ssh-agent and ssh-add all the keys you need to it.


# start the agent and capture its environment in the current shell
eval `ssh-agent`

# add keys needed to connect to the different accounts
ssh-add /path/to/first/ssh/key
ssh-add /path/to/second/ssh/key

# do the copying
scp first@host1.example.com:file1 second@host2.example.com:file2

EDIT: I was wrong about the transfer through localhost. The manual I read didn't clarify it.

You have to setup a key pair for authentication from server1 to server2. So, you must be able to connect from your system to server1 and from server1 to server2. You effectively run ssh user@server1 scp -r files user@server2:files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.