I am trying to download a directory from my cloud server to my local, using scp, with the following:

scp -i ./.ssh/mykey.pem -r -p admin@

admin is of course the remote, for which I need to key, while is the local.

I receive however the error message:

Host key verification failed.
lost connection

If I try to connect through ssh to my server using ssh -i ./.ssh/mykey.pem admin@ it does work.

Could anyone point me to what I am doing wrong?


For copying to the local server, you don't need the Just this will do:

scp -i ./.ssh/mykey.pem -r -p admin@ /var/lib/mongod

With the, scp makes another SSH connection to the server at and acts as if it was copying between two remotes. The SSH server at might be failing host key verification.


From Man page,

scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ... [[user@]host2:]file2

So when you are using at last portion, scp recognized that as host2. So then scp will try to logged in at host with current username, based on the identity file (./.ssh/mykey.pem) and returns error, may be because there is no information about host2. So just following will work fine,

$scp -i ./.ssh/mykey.pem -r -p admin@ /var/lib/mongodb


$cd /var/lib/mongodb
$scp -i ./.ssh/mykey.pem -r -p admin@ .

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.