I am trying to copy files from one server directly to another, bypassing my local computer.

I did

scp -r usrname@server1.com:~/data/* usrname@server2.com:~/data/
Host key verification failed.
lost connection

Is this even possible? How may I fix it?

  • Can you post the output of following command- scp -r -v usrname@server1.com:~/data/* usrname@server2.com:~/data/ – pragmatic Feb 12 '15 at 10:30

Something I use fairly often when there is no connection possible between the two servers

scp -3 user@server1:/path/to/file user@server2:/path/to/file


-3 Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. Note that this option disables the progress meter.

Assuming youu have a good connection to both, its not too slow.


Yes this is possible, but only if server1.com can reach server2.com by using that name. If not you will probably get a message: ssh: connect to host server2 port 22: Connection refused

The man page for scp clearly states that it copies between hosts on a network and that:

Copies between two remote hosts are also permitted.

What you should do (once) is ssh to username@server1.com and from there ssh to username@server2.com. Answer the authenticity question you'll get with yes, to get rid of the host key verification message while doing the scp

You might have to enable the forwarding agent with:

scp -o "ForwardAgent yes" -r usrname@server1.com:~/data/* usrname@server2.com:~/data/

But make sure you realise the danger in that (man ssh_config)

  • I just sshed from server1.com to server2.com, and I indeed answered the question and succeeded. Then, I go back to my local computer, do it again, and get the server2.com's password prompt. But it fails there with:Permission denied (publickey,keyboard-interactive). lost connection – Sibbs Gambling Feb 12 '15 at 8:41
  • 1
    @SibbsGambling I think this relies on forwarding your private key. Can you login to both servers without providing a password? Could you login from server1 to server2 without providing a password. You might have to set "ForwardAgent yes". – Anthon Feb 12 '15 at 8:59

Firstly you need to check i you are able to ssh to server2 without any error, if you get the same error, then please open the file ~/.ssh/known_hosts and search the server2 key and delete it.

Then check if you are able to ping the server by the host name

If not then please edit both the server host file as mentioned below

 #vi /etc/hosts  
 server1 192.186.x.x  
 server2 192.186.x.xx   
 :wq   ---> to save  

After you are done with this cd to the location of the file which you want to copy to the server2

the scp file_name user@server2:/path_to_the_directory ---> you can use the IP instead of the hostname you can mention -R to copy a directory.


Check if ~/.ssh/known_hosts have proper records for both servers

Check also if server1 have proper ~/.ssh/known_hosts record for server2


You can use this below command to copy file from one server to other:

scp source_user@source_remote_host:/usr/bin/mysql_backup.sh \

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.