Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 can connect to another Ubuntu machine in my LAN via SSH. On both of then PC's I installed openssh-server but from another Ubuntu computer I can not connect to my PC via SSH and I got this error:

Host key verification failed...

share|improve this question

migrated from May 28 '11 at 12:38

This question came from our site for professional and enthusiast programmers.

Dó you use host names or IP-addresses? – Thorbjørn Ravn Andersen May 27 '12 at 13:21
Not similar but I got the same error but due to a different problem:… – zengr Aug 28 '13 at 19:18
up vote 79 down vote accepted

"Host key verification failed" means that the host key of the remote host was changed.

Ssh stores the host keys of the remote hosts in ~/.ssh/known_hosts. You can either edit that text file manually and remove the old key (you can see the line number in the error message), or use

ssh-keygen -R hostname

(which I learnt from the answer to Is it possible to remove a particular host key from SSH's known_hosts file?).

share|improve this answer

If you are running in certain remote/scripting situations where you lack interactive access to the prompt-to-add-hostkey, work around it like this:

$ ssh -o StrictHostKeyChecking=no uptime

Warning: Permanently added ',' (RSA) to the list of known hosts.

share|improve this answer
+1, this is an ugly solution, but in some cases of automated monitoring processes that work with dymaic ip-connected devices, this is a simple and acceptable solution. – Ninsuo Nov 11 '13 at 14:34
+1 For example, for Jenkins executions, this is a good solution. Thanks – Lobo Feb 5 '15 at 10:02

Also sometimes there is situation when you are working on serial console, then checking above command in verbose mode -v will show you /dev/tty does not exist, while it does.

ssh -v user@hostname

In above case just remove /dev/tty and create a symlink of /dev/ttyS0 to /dev/tty.

rm /dev/tty
ln -s /dev/ttyS0 /dev/tty

As an alternative, add to the remote location, so password is not prompted and you get login access.

share|improve this answer
+1 for advising to use -v parameter; this can help a lot when debugging ssh problems. – daniel kullmann Jul 24 '12 at 19:10
Agreed. May save my bacon, thanks. – djhaskin987 Mar 31 '14 at 19:24

In my case, this was caused by a udev problem - there was no /dev/tty device node. The solution for me was just:

sudo mknod -m 666 /dev/tty c 5 0

share|improve this answer

This is an old thread and I just ran across this answer, I will just add what I did to solve this.

ssh-keygen -f "/home/USER/.ssh/known_hosts" -R HOSTNAME

I just looked at the error message that it threw at me and it said to run that command in order to remove it from the list of hosts. After that I did the following:

ssh-copy-id HOSTNAME

Than I followed the prompts from there until I was able to ssh into the server.

share|improve this answer
As this command I am getting as suggestion in ubuntu 12.4. – MaNKuR May 31 '15 at 18:09
this help me +1 – Wondering Coder Jun 9 at 2:27

Well, it simply because the second ubuntu requires connection by key and not password.

I suggest you use sudo dpkg-reconfigure openssh-server on your pc, and then it should work properly. It will reset the configuration for openssh and should come back to a default password authentication.

Second possibility is that there's already a key for your other ubuntu in you PC, and that it changed thus being not recognized anymore. In this case, you'll have to edit the file .ssh/authorized_keys to remove the problematic line identifying your ubuntu.

share|improve this answer

pico ~/.ssh/known_hosts and delete all lines, after just reconnect and you will get a new key.

share|improve this answer
This is a dangerous solution, because you will remove ALL your host keys. The accepted solution, ssh-keygen -R hostname is better. – msanford Mar 24 '14 at 20:52

You should change your key in this way: From your given error find which host-key changed for example: Offending ECDSA key in /Users/user-name/.ssh/known_hosts:5 said 5th key changed, so do this:

sed -i '5d' ~/.ssh/known_hosts

Notice: you must be root or have privilege for sudo.

share|improve this answer
No, unless you are doing it for someone else, it does not require root nor sudo. You are editing the file in your home directory. Second: for the command to work it requires GNU sed. – techraf Mar 13 at 16:00
Maybe you right but I tried to ssh from Mac OSX to ubuntu-server and I have to do that. by the way thank you for your comment. – Amir.A.G Mar 14 at 16:44

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.