Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I am trying to copy a file from one machine to another machine via ssh. Both machines are Ubuntu servers. Both machines have exchaged keys so that they can log into each other without passwords.

The command I have looks like this (details changed for privacy, of course):

scp -i /var/www/place/.ssh/id_rsa file.tar.gz otherserver@

However, every time I run it, I get this error:

Could not create directory '/var/www/.ssh'.
Host key verification failed.
lost connection

It seems like the scp command is trying to create a directory called .ssh one level up from place.

What's going on here? Does scp need to create some kind of temporary directory in order to execute?

The user account that is running the command has read/write permissions within /var/www/place, but not /var/www, so how do I get this scp command to run?

(Please be aware I am not very experienced with Linux command line stuff, so please make answers verbose and simple. Thanks for your understanding.)

share|improve this question
My best bet that the user you're trying to use to log in has /var/www as his homedirectory, but /var/www is not writeable to this user. Clarification: I meant the client side. If this user you want to do ssh with has never use ssh before, ssh/scp will want to create a $HOME/.ssh directory where he will put the file known_hosts into. This file is used to store the public keys of remote hosts. That would also explain the "Host key verification failed" part. – Alexander Janssen Apr 23 '12 at 8:54
@Alex: But shouldn't specifying the full path of the id_rsa file negate the need to look in the home path for the .ssh authentication files? – Questioner Apr 23 '12 at 8:56
No, it doesn't matter at all where the client put's his private key. It can even be on a USB thumbdrive or on a smartcard. Do some simple check: 1) What is the local user? 2) What's his homedirectory? 3) Does the homedirectory belong to thos user and is it writeable? – Alexander Janssen Apr 23 '12 at 8:58
up vote 2 down vote accepted

The problem is unrelated to the public key authentication you have set up. Besides your private and public keys, SSH will also store the host key of each host you connect to in your ~/.ssh directory under a file called known_hosts. The errors you're seeing are from SSH's attempts to initially create this file.

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.