4

When I try to ssh to my server from a linux computer with debian, I just get

Host key verification failed.

The only help I found online was deleting the key from ~/.ssh/known_hosts... well I did not only that, I deleted the whole ~/.ssh just to be sure, and it didn't help either, I still have Host key verification failed. error.

Karel Bílek
  • 1,859
  • 5
  • 20
  • 26

3 Answers3

11

OK, answered.

When I run ssh with -v option, it showed me the actual error.

It was caused by mistakenly setting wrong access rights to /dev/tty, whatever that is, and ssh somehow didn't like it. sudo chmod 666 /dev/tty seemed to fix it.

Karel Bílek
  • 1,859
  • 5
  • 20
  • 26
5

So the poster's problem has been resolved. But in case others come to this question by searching and their symptoms are not coming from the same cause:

Deleting ~/.ssh/known_hosts (or just the offending line in it) will purge the cached host key. However, there is also a system-wide cache, which will be stored someplace like /etc/ssh/ssh_known_hosts. Host keys won't be cached there unless that's specifically requested. But if you're having host key verification issues, have a look in both of these files.

dubiousjim
  • 2,648
  • 19
  • 27
1

It is also possible to run into this issue in various other ways, especially when dealing with Windows which may have several implementations of SSH tacked on to it.

I ran into this when ssh'ing into a Windows 10 machine that was running SSH server under Cygwin. When you run ssh from that prompt, it runs the cygwin version of ssh, which uses ~/.ssh to store the ssh files --- under cygwin that is /home/username.

However, if you run git from that same prompt, and Git has been installed via Windows (which in my case it had been), it uses the ssh files from C:\Users\username.ssh.

Normally you run ssh hostname to cache the host key for git, but in this case it does not work, since there are different known_hosts files.

Once I copied the key from one known_hosts file to the other, the git commands worked fine.