I have the fingerprint from the remote host which is said to be its public key fingerprint according to What is a SSH key fingerprint and how is it generated?.
Asking for the host fingerprint:
ssh-keygen -lf <(ssh-keyscan MY_SERVER.com 2>/dev/null)
gives for example:
2048 SHA256:asdfaewfbadsdasfasgasefasfasdvfth56sdghjum7 id_rsa (RSA)
and the following line:
ssh -o visualhostkey=yes -o FingerprintHash=SHA256 MY_SERVER.com
reaches the same:
2048 SHA256:asdfaewfbadsdasfasgasefasfasdvfth56sdghjum7 id_rsa (RSA)
and should be enough to say that the connection is the expected one.
On the other hand, I have the public (MY_PUBLIC_SSH_KEY) + private (MY_PRIVATE_SSH_KEY) ssh key pair at hand for the server. I can connect to the server with the private ssh key, and then with the right login_name, I do not need to enter a password anymore, which is the idea of the ssh key. Therefore, the public key that is saved on the server must also be the right one:
ssh -o visualhostkey=yes -o FingerprintHash=SHA256 -i MY_PRIVATE_SSH_KEY MY_LOGIN_NAME@MY_SERVER.com
# # or the same:
# ssh -o visualhostkey=yes -o FingerprintHash=SHA256 -i MY_PRIVATE_SSH_KEY MY_LOGIN_NAME@MY_SERVER.com
But the fingerprint of the public ssh key MY_PUBLIC_SSH_KEY does not give the same fingerprint as that of the server. It does not use 2048 at the bit size of the underlying key, but the default 4096:
ssh-keygen -b 2048 -t rsa -lf id_rsa.pub
gives:
4096 SHA256:asfawefbrgaqeffaefafrew546rtghhdhdfhsert45y id_rsa (RSA)
The public key that I have at hand looks like:
ssh-rsa AAAABasfjjeiaj;jkaskl;dfkjsafe9w0fo-0oas[kfoamks;dfk...(4096 bits size)== MY_FILE_NAME
while that on the server (cat .ssh/id_rsa.pub) is:
ssh-rsa AAAABasfjieajfjaei;jfi;ajisejifjdfasdf(2048 bits size)...== ANOTHER_DIFFERENT_FILENAME
The fingerprints are not the same because the underlying key lengths and the added comment at the end are different. Yet, they should be the same thing. The -b parameter does not react to anything, and I can even use -t ecdsa and the fingerprint will still be the same, as if it always just gives something that is already fixed by the public key content itself.
ssh-keygen always defaults to 4096 bit key size, I need 2048, the -b parameter does not seem to work.
From this I see that either the public key has changed to the better 4096 standard and the ssh-keygen might default to that -t parameter which was used in the new public key while the server still outputs the old fingerprint for whatever reason, or the fingerprint of the public key cannot be the same as the fingerprint of the host since they are calculated from different bit sizes.
I also found that you can change the default of ssh-keygen, see Can you make default client key length larger for ssh-keygen?, but should it not just also work out with the -b parameter? 4096 is a good default, I do not want to change it. Or do I oversee something general here?
I know from other Q/A that it should already be enough to do the two steps above that reach the same fingerprint. But then I still want to know what I should do with the fingerprint of that 4096 bit public key at all if I do not need it for the successful comparison above.
I must have misunderstood something. With a key pair at hand, and the private key working, how can I find the "counterpart public key" on the server and compare fingerprints?