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 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, 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.

  • What is the significance of the equals sign at the end of ssh-rsa AAAA1234.....=? I opened up my public key and it does not end with an equals sign, instead the format looks like: ssh-rsa AAAA1234.... user@hostname. How would I insert that into my known_hosts file?
    – wheeler
    Oct 23, 2017 at 18:12
  • 2
    @wheeler Insert it to the known hosts as it is. The equal sign is just a padding of base64 encoding.
    – Jakuje
    Oct 24, 2017 at 14:24
  • 1
    why isnt there just a simple cmd to add a public key to known_hosts? If I got it from an other trusted source, its much better than using the often proposed ssh-keyscan which depends on trust-on-first-use
    – Jeno
    Jun 8, 2020 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.