Adding a Public Key to known_hosts File
I have downloaded the ECDSA public key (ssh_host_ecdsa_key.pub) from another machine. I want to add the key to my local known_hosts file before connecting to it via SSH. How can I do that manually (without comparing MD5 hashes on the screen)?
I'm running Ubuntu 15.04 on my local machine.
1 Answer
Manual page for sshd(8) describes the format of known_hosts file:
Each line in these files contains the following fields: markers (optional), hostnames, bits, exponent, modulus, comment. The fields are separated by spaces.
If your public key for your host looks like this:
ssh-rsa AAAA1234.....=So just putting this line into your ~/.ssh/known_hosts file:
your.host.name,0.0.0.0 ssh-rsa AAAA1234.....=where you will exchange hostname and ip for your host.
Now it depends if you have ssh option HashKnownHosts turned on. If not, you are done. Otherwise (e.g. on current Ubuntu releases) you will need to hash this file using ssh-keygen -H -f ~/.ssh/known_hosts.