I am trying to understand the relationship between fingerprint of SSH server's public key and known_hosts
file.
There are two SSH servers with same public key. I, the client has the private key. I login to the first SSH server,since it is asking me for the first time, I have say yes to "do you trust the fingerprint...".
The server sends the public key and the hash of the public key? or the hash is calculated by the client using the public key received by the server?
Is the fingerprint itself added to known_hosts
file? I tried to grep
the fingerprint that was provided in the known_hosts file but it produced no output. So what exactly is being added to known_hosts file when trust the fingerprint?
Secondly, when I swap out the first SSH server with a second one, the public key is the same but when I ssh into it, I get the fingerprint has changed? How is that possible? Which public key is being used to calculate the fingerprint? The public key of key pair for which I have the corresponding private key? If that's the case, they server's public key has not changed so why different fingerprint? or is it a public key from /etc/ssh
directory? If that's the case, I don't have the private key for that public key. How would the session, continue then?
What things go into calculating the fingerprint?