I am trying to scp the files from machineB to machineA. I need to run the scp command from machineA to copy files from machineB to machineA.

The file that I need to copy from machineB is -


And where I need to copy the file into machineA is -


in which I have root access as well and /data01/primary has only root credentials. Below is the ls -lt on machineA

david@machineA:/$ ls -lt

drwxr-xr-x   3 root root  4096 Nov  7 17:43 data02
drwxr-xr-x   3 root root  4096 Nov  7 17:42 data01
drwxr-xr-x   4 root root  4096 Nov  7 17:26 opt

So I was trying the below scp command on machineA to copy the files -

scp david@machineB:/bat/data/snapshot/5.data root@machineA:/data01/primary

but I am always getting -

Host key verification failed.

I do have root access to machineA but not root access to machineB. And I can ping machineB from machineA as well. And both machines are in production domain as well.


Minor tips

If you're logged into machineA as root then I don't think it's necessary to say the root@machineA:/... bit, you can say it a little less verbosely like this:

$ scp david@machineB:/bat/data/snapshot/5.data /data01/primary

I always say target directories like this too, just so it's more obvious what's going to happen:

$ scp david@machineB:/bat/data/snapshot/5.data /data01/primary/.

Your issue

But I don't think that's the root cause of your error message:

Host key verification failed.

Rather this message usually means you have a invalid and/or out of sync host key in your /etc/.ssh/known_hosts file.

You can confirm with this command:

$ ssh-keygen -R <hostname>


$ ssh-keygen -R skinner
# Host skinner found: line 1 type RSA
# Host skinner found: line 125 type RSA
/home/saml/.ssh/known_hosts updated.
Original contents retained as /home/saml/.ssh/known_hosts.old

Skipping the host check

If you know what you're doing and don't care about the host check you can temporarily disable it like so:

$ scp -o StrictHostKeyChecking=no \
    david@machineB:/bat/data/snapshot/5.data /data01/primary/.


  • Thanks for detailed suggestion. I noticed very strange issue here. When I am running my command like this - scp david@machineB:/bat/data/snapshot/5.data /data01/primary/. from machineA, it works fine. But if I am running my same command like this scp david@machineB:/bat/data/snapshot/5.data root@machineA:/data01/primary from machineA, it always gives me the above exception.. Any thoughts why? – SSH Dec 17 '13 at 5:38
  • @SSH - I would be suspicious of the known_hosts files under both accounts on machineA & B. You can debug ssh and scp by adding increasing numbers of -v switches. Example, scp -vv david@machineB:.... . The reason should be fairly obvious with the increased debugging. – slm Dec 17 '13 at 6:13
  • I am slightly new to all these things. If you can guide me step by step what I should do, then I might be able to figure out few things and also learn quite a bit of things as well.. – SSH Dec 17 '13 at 6:17
  • @SSH - sure try your command with the extra -vv switches. Example: scp -vv david@machineB:/bat/data/snapshot/5.data root@machineA:/data01/primary |& tee logfile.txt. This will capture the output into the file logfile.txt. – slm Dec 17 '13 at 6:24
  • I just did that and it copied bunch of stuffs in the logfile.txt file and when I opened that file, most of the stuff are going above my head. :( Now what should I do? – SSH Dec 17 '13 at 6:28

“Host key verification failed” means that you have previously connected to a machine by that name, and you're now connecting to a different machine by the same name. In an ideal world, this would be a sure-fire sign that somebody is hijacking your connection, and you're attempting to connect to the attacker's machine instead of the one you wanted to connect you. Therefore SSH rejects the connection attempt.

Since you're copying between two remote machines, either of them could be the culprit. To see which one it is, run a command on one machine, e.g. ssh david@machineB true and ssh root@machineA true.

In a comment, I see that you're seeing this error when you attempt to reach machineA from itself. This is always safe (unless there are oddities in name resolution that cause your machine name to refer to another machine). The most likely explanation is that you reinstalled your machine at some point, causing your host key to change, but you reused the old host name.

Ssh stores the information about past connections in the file ~/.ssh/known_hosts. If you've determined that an entry there is obsolete (because the machine has been reinstalled), remove it:

ssh-add -R root@machineA

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.