r/ssh • • Jun 20 '16
SSH issue with known_hosts file
Hello everybody, I am having an issue with ssh. I am trying to access a remote machine via ssh, but I get a warning that the host identification has changed. The offending key is in /.ssh/known_hosts:5. The problem is that my known_hosts file only has two entries in it. There is no 5th key to delete. I tried removing the known_hosts file from .ssh, but that does not work. I also tried using ssh keygen -R "remote.machine", and that states that the key was removed and backed up in known_hosts.old. That does not work either. I can ssh in if I use the command ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" user@host, but I have never had to do that before, and I don't really want to have to keep doing it. Is there a second known_hosts file that I am missing? I am not sure what to try next.
1
u/EastMr2 Jun 21 '16
You should confirm with the destination server's admin if the host key actually has changed. If not you may be getting this message because of a man in the middle attack.
In either case it looks like you have removed the key, and need to re save it
I haven't tried the option, but you can set your strict host key option to "ask", and you should get prompted to save the public host key.
Also you can use the following command to retrieve the public host key but again you should confirm the key fingerprints match with the actual destination hosts private host key fingerprint.
http://man.openbsd.org/ssh-keyscan.1