These are not different formats of known_hosts
, but different key types (ssh-rsa
and ecdsa-sha2-nistp256
- well described in manual page for sshd
). Server usually have more host keys of different types to provide wider compatibility with different clients.
If you are on the server, you can find all the host keys and print their public keys using, but the line is not in the same format as :
$ cat /etc/ssh/ssh_host_*.pub ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEJJEs165NgdEcD94Xg3ySFA/qgkfytxNCX1X3pB2SPgU/mHLGXCXM8+VqMBXocM8OMOq2L0fDGr5mI+nGqjhNU= user@host
The format that is accepted by known_hosts
file can be obtained using (from the server to achieve the authenticity of the keys):
$ ssh-keyscan 11.22.33.44 11.22.33.44 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEJJEs165NgdEcD94Xg3ySFA/qgkfytxNCX1X3pB2SPgU/mHLGXCXM8+VqMBXocM8OMOq2L0fDGr5mI+nGqjhNU= #[...]
This prints the format you can directly store in the client known_hosts
.
For the whole picture (from manual page):
Each line in these files contains the following fields: markers (optional), hostnames, bits, exponent, modulus, comment. The fields are separated by spaces.
(though it looks non-consistent with what is generated: hostname, key-type, key data (base64)) - I will check that later, since it is not important for the question