Deleted known_hosts file on private server, how do I get it back?

In my ignorance I deleted the known_hosts file on private server. I am not sure what the file type is supposed to be. In general, I have been having problems with ssh and passwords. For some reason, despite having generated a private/public key pair and successfully saving the .pub file onto the private server @ ~/.ssh I am still being prompted for passwords. That is what lead me to deleting the contents of the directory and trying to start over.

If not knowing the host (which identifies itself with some sort of key similar to the ssh key during login negotiation), the client informs you accordingly and asks you if you really want to continue / connect. You say "yes", the client stores the key, and knows the host the next time you connect.

1 Like

Hi,

The obvious answer is: Restore it from your backup. If you do not have one, or realize that your backup does not allow restoration, that may be a serious problem.

The file known_hosts does not really have to do with authentication. You may use ssh-keyscan to gather the keys from different hosts, or just initiate an ssh command to that host, like RudiC said. You may temporarily ignore the host-keys with an ssh command like this:

ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ...

Authentication is described within the OpenSSH manpages. See here for details:

OpenSSH: Manual Pages

Check especially the AUTHENTICATION and FILES sections in ssh(1) command there for general descriptions and required file permissions. As reading this there, I would advise that all "recommended file settings" there are strictly done that way. I'm not sure that this wouldn't cause errors if not done so.