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 [email protected]:/var/lib/mongodb

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 [email protected] it does work.

Could anyone point me to what I am doing wrong?

2 Answers 2


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

scp -i ./.ssh/mykey.pem -r -p [email protected]:/var/lib/mongodb /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 [email protected]:/var/lib/mongodb /var/lib/mongodb


$cd /var/lib/mongodb
$scp -i ./.ssh/mykey.pem -r -p [email protected]:/var/lib/mongodb .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .