4

So recently there were news of OpenSSH dropping support for SHA-1 logins and I am trying to understand which format they are referring to. Since years i've been generating keys via ssh-keygen -t rsa -b 2048. Is this the type not recommended anymore and I should switch for example, to ECDSA?

In this man page, https://www.man7.org/linux/man-pages/man1/ssh-keygen.1.html , the default option rsa for the -t argument explains that the chosen option is using the SHA1 signature, so one should choose rsa-sha2-256 for example.

I tried checking the type of the key with ssh-keygen -l -f key and it shows me that it is indeed SHA256 type. If so, then it solves my question but some clarity would be welcome. thank you!

Source of news: https://www.zdnet.com/article/openssh-to-deprecate-sha-1-logins-due-to-security-risk/

10

The key format has not changed. The only thing that changes is the signature format that's sent during each authentication handshake.

What makes everything confusing is that originally in SSHv2, the key type and the signature type used to be defined in combination. (For example, the same "ssh-rsa" identifier was defined to mean RSA keys and RSA/SHA-1 signatures.) So changing the signature process would have meant assigning a new key type identifier, and that would have meant generating a new key...

However, protocol extensions have been developed to avoid this, and modern SSH clients will automatically negotiate the signature types whenever RSA keys are involved. If you connect with ssh -v you will notice a few additional packets being exchanged:

debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,
                            rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,
                            ecdsa-sha2-nistp521>

So you can continue using "ssh-rsa" keys – you only need to upgrade the software on both ends to something reasonably recent, and it will automatically start producing "rsa-sha2-256" signatures from that key. (For example, you might need to install a new version of PuTTY and Pageant, and you might have troubles with older versions of gpg-agent.)

Signatures in ssh-keygen

the default option rsa for the -t argument explains that the chosen option is using the SHA1 signature, so one should choose rsa-sha2-256 for example.

This applies when issuing certificates, but is irrelevant when generating plain keys.

Each certificate is signed by the parent CA at the time it is issued. This long-term signature is stored in the certificate itself (and it's very important to realize that this is a different thing from the short-term signatures that are made during each connection and then thrown away). That's why many HTTPS (X.509) certificates had to be replaced – the issuing CA had stamped them with RSA/SHA-1 signatures.

OpenSSH has also created its own certificate format, which is what the manual page is referring to. These so-called "SSH certificates" are not just regular SSH keys – they're additionaly signed by e.g. your workplace CA. So if you have files whose names end with *-cert.pub, you might need to have those re-issued. (Use ssh-keygen -Lf <file> to check how they were signed).

But plain SSH keys do not hold any long-term signature inside – they're only used to make temporary signatures during each connection. So there is nothing that needs replacement in the key itself.

The -l option

I tried checking the type of the key with ssh-keygen -l -f key and it shows me that it is indeed SHA256 type

No, that is not what ssh-keygen shows at all. The -l option is showing you the key's "fingerprint" and it's telling you that it used SHA256 to compute this fingerprint – but it has nothing to do with the key's type, nor with how the key will actually be used. The fingerprint is just a hash that was computed right now in order to be shown to you.

(Remember that previously SSH software used to show MD5-based key fingerprints – even though there was no MD5 usage in the actual SSHv2 protocol.)

Other key types

Is this the type not recommended anymore and I should switch for example, to ECDSA?

From what I know (i.e. from what I gathered on Security.SE), RSA as a signature algorithm is still strong – problems mostly just occur when trying to use RSA as an encryption algorithm, and that's not an issue with SSHv2. (Well, the ever-increasing key size is not great either.)

ECDSA has its own problems – it is difficult to get its implementation right and certain kinds of programmer mistakes can be disastrous. If you had to switch, EdDSA (that is ssh-ed25519 or ssh-ed448) would be a better option.

| improve this answer | |
  • Very informative post! Thank you. What kind of mistakes are common with ECDSA? I did once use a key with ed25519 algorithm and gnome-keyring did not like that (in some old version of ubuntu). – strudelj nudelj Jun 1 at 9:43
  • 1
    Since then, GNOME Keyring has switched to using OpenSSH's ssh-agent instead of implementing an internal agent. The most common example is that originally ECDSA signatures had to include some amount of random & unique data (a 'nonce'), and if it was accidentally not unique, it could result in leaking the entire private key. (Apparently it's how they jailbroke PlayStation 3.) There is a recent spec describing a way to use ECDSA with deterministic nonces to avoid this problem, but I'm not sure how widely it is adopted. – user1686 Jun 1 at 11:43
  • 1
    The change to SHA256-base64 (instead of md5-hex) fingerprint by default was 6.8 in 2015, but you can override and do old-style fingerprints, see superuser.com/questions/929566/… (Aside from that wish I could +2) – dave_thompson_085 Jun 1 at 20:16

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.