Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I attempt to perform a

scp user1@host1:somfile user2@host2:somfile

I get

Host key verification failed.

lost connection

The authentication to both hosts is ssh-key based, however for security reasons the private key is only stored on the host that issues the above command.

Another complication in this setup is, that host2 is SFTP-only, so no shell access there.

I tested with an older openssl/openssh (Debian lenny openssh-client 5.1) combination and a with latest openssl/openssh releases built from source (openssl 1.0.0c, openssh 5.8) as well. Same behavior.

It's also woth to mention that executing

scp user1@host1:somfile somfile

scp somfile user2@host2:somfile

sequentially through a temp file works.

What am I'm doing wrong here?

share|improve this question
The ssh-agent is running btw. As this is also indicated through the fact that the sequential commands are working fine – garbeam Feb 4 '11 at 11:01
Re "host2 is SFTP-only" - the OpenSSH scp command does not use SFTP. – grawity Feb 4 '11 at 11:32
up vote 6 down vote accepted

Until OpenSSH 5.7, copying between two hosts is done directly. In other words, the connection to host2 is made from host1, using host1's list of known hostkeys.

  • You can add host2 to the known_hosts file at host1, by simply connecting to it. Then use agent forwarding to let host1 authenticate using your locally running agent:

    ssh -oForwardAgent=yes host1 ssh host2 true
    scp -oForwardAgent=yes user1@host1:somfile user2@host2:

    (ssh has a shortcut -A for this option. It can also be added to ~/.ssh/config.)

  • In 5.7 and later, you can use scp -3 to force the copy to be made through your computer:

    scp -3 user1@host1:somfile user2@host2:

    This will probably be much slower because of host1 → you → host2.

share|improve this answer

Don't you have ssh-agent running, do you?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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