Adding a Public Key to known_hosts File
Solution 1:
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
.