I am trying to SSH into my fresh Ubuntu 12.04 server. At the client I have deleted known_hosts. SSH to the host for the first time has it offering me an ECDSA key to verify. The problem is I know how to get the RSA key and verify it but I don't know how to get the ECDSA key.

How can I force SSH to prompt with the RSA key and store it if I approve?

I have tried:

ssh -o RSAAuthentication=yes user@server

Unfortunately this gives me an ECDSA key and the Are you sure you want to continue connecting (yes/no)? message.

  • Note option RSAAuthentication (and the related RhostsRSAAuthentication also) was about authenticating the client, not the host, and only in SSHv1, which was broken and obsolete last century. OpenSSH 7.5 in 2017 (well after this Q was asked) removed SSHv1 entirely and disabled related options. The option for PKC client auth in SSHv2 is PubkeyAuthentication. The server always uses PKC auth, so there is no option to enable it, only to tailor it with HostKeyAlgorithms as correctly answered. – dave_thompson_085 Jun 22 at 2:13

You can also tell the server what algorithm to use from the client (for example if you already have the rsa fingerprint written down and are physically far from the server)

  ssh -oHostKeyAlgorithms='ssh-rsa' host
up vote 12 down vote accepted

Don't use RSA since ECDSA is the new default. Newer things are sometimes better. Default things are often better for the convenience of most people. A new thing that is a default thing is very probably better for most people.

On the server do this:

ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub

and record that number.

On the client you can SSH to the host and if and when you see that same number, you can answer the prompt

Are you sure you want to continue connecting (yes/no)?

affirmatively. Then the ECDSA key will get recorded on the client in the known_hosts file at the default location so that future use of ssh will not require you to acknowledge the identity of the remote host.

Addendum:

If you will ever stop using that remote host, perhaps because it is a cloud server that you have deleted, then delete the record from the known_hosts file via:

ssh-keygen -R 255.255.255.255

or something like that.

  • Sometimes this isn't possible, in my case a java dev is using an old SFTP library that only supports known hosts files in RSA format and won't accept ECDSA (who knew) – Rumbles Jun 5 '17 at 14:36

Yes, OK switch to ECDSA soon, but in the meantime try this:

ssh -oHostKeyAlgorithms=ssh-rsa -o FingerprintHash=md5 user@example.com
  • 2
    Can you explain how this is different from the top-voted answer? How is your answer unique? – schroeder Dec 18 '15 at 3:33
  • 2
    Sure. A recent version of sshd switched from defaulting to RSA to defaulting ECDSA. It also appears to have updated the fingerprint hashing algorithm from MD5 to something more modern. I launch a lot of EC2 instances, and have written a script that runs on instance launch which tags the instance with the RSA host key's MD5 fingerprint. Until I update my tagging script, I have to specify both RSA and MD5 to verify my host keys. I'm guessing the OP might be having a similar problem. – bonkydog Dec 19 '15 at 21:54
  • 1
    You need to edit your answer to include these details – schroeder Dec 19 '15 at 22:04
  • @bonkydog is 100% correct - this was my issue as well. – Jon G - Megaphone Tech Jul 22 '16 at 18:20

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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