193

As someone who knows little about cryptography, I wonder about the choice I make when creating ssh-keys.

ssh-keygen -t type, where type is either of dsa,rsa and ecdsa.

Googling can give some information about differences between the types, but not anything conclusive. So my question is, are there any "easy" answers for developers/system administrators with little cryptography knowledge, when to choose which key type?

I'm hoping for an answer in the style of "Use DSA for X and Y, RSA for Z, and ECDSA for everything else", but I also realise it's quite possible such simple answers are not available.

5
  • 10
    Only RSA is an encryption algorithm. Both DSA and ECDSA are used for digital signing - the latter being an Elliptic Curve implementation of DSA (Digital Signature Algorithm). Elliptic curve cryptography is able to provide the same security level as RSA with a smaller key and is a "lighter calculation" workload-wise. So, use RSA for encryption, DSA for signing and ECDSA for signing on mobile devices. Oct 30, 2012 at 13:01
  • related: ECDSA vs ECDH vs Ed25519 vs Curve25519 Sep 29, 2016 at 7:55
  • 2
    @HenningKlevjer: Although RSA can do both encryption and signing, SSH2 uses it only for signing. Mar 24, 2017 at 13:14
  • FYI If you want to determine type of an existing key: ssh-keygen -l -f key_file
    – user30473
    Oct 12, 2020 at 12:08
  • wiki.archlinux.org/index.php/… Nov 27, 2020 at 11:28

4 Answers 4

144

In practice, a RSA key will work everywhere. ECDSA support is newer, so some old client or server may have trouble with ECDSA keys. A DSA key used to work everywhere, as per the SSH standard (RFC 4251 and subsequent), but this changed recently: OpenSSH 7.0 and higher no longer accept DSA keys by default.

ECDSA is computationally lighter, but you'll need a really small client or server (say 50 MHz embedded ARM processor) to notice the difference.

Right now, there is no security-related reason to prefer one type over any other, assuming large enough keys (2048 bits for RSA or DSA, 256 bits for ECDSA); key size is specified with the -b parameter. However, some ssh-keygen versions may reject DSA keys of size other than 1024 bits, which is currently unbroken, but arguably not as robust as could be wished for. So, if you indulge in some slight paranoia, you might prefer RSA.

To sum up, do ssh-keygen -t rsa -b 2048 and you will be happy.

13
  • 18
    DSA always makes me uneasy because a signature generated with a broken RNG can compromise the key. RSA keys have an easier to understand and less worrisome failure mode: generating a key with a broken RNG compromises the key, running a session with a broken RNG compromises the session at most. Oct 30, 2012 at 13:26
  • 5
    No. In fact, everything that was revealed in that affair only confirms what was already known, i.e. that when big governmental agencies spy on people, then don't do it by trying to break cryptography upfront; they rather work around it. In the SSH case, they would collect metadata (this client machine connects to that server) that is not protected by the SSH protocol, regardless of the server key algorithm or size. Sep 5, 2014 at 11:28
  • 5
    "As per the SSH standard (RFC 4251 and subsequent), a DSA key will work everywhere" - In practice, that is no longer true. OpenSSH silently disabled DSA somewhere around 7.0 or 7.1.
    – user29925
    Oct 3, 2015 at 18:26
  • 3
    Correction on "how gov't spies on people": Sometimes they do attack the crypto. weakdh.org mentions that one NSA attack on VPNs might use their disclosed vulnerability. So don't get complacent. :-P Feb 13, 2017 at 18:18
  • 3
    @Evi1M4chine The "NSA backdoor in RSA" was a backdoor in a random-number-generator by RSA Corporation, wasn't it? Nothing to do with the algorithm also called RSA.
    – user253751
    Mar 24, 2017 at 1:19
27

As gilles says DSA is risky because if you make signatures (and using your key with a ssh client to log in is effectively making signatures) on a box with a bad RNG your key can be compromised. AIUI this made Debian basically abandon DSA for keys used on their infrastructure in light of the Debian OpenSSL random number generator fiasco.

http://meyering.net/nuke-your-DSA-keys/

ECDSA is relatively new, from some quick searching it seems it was introduced in 5.7. Afaict most of these systems are out of support and should probably be migrated but we all know that doesn't happen somtimes. For example, Debian squeeze and ubuntu lucid. ECDSA has advantages in that a key can be much smaller than a RSA or DSA key for the same level of (presumed) security. Unfortunately it shares the disadvantage of DSA of being sensitive to bad random number generators. There are also concerns that the elliptic curves traditionally used may have been backdoored.

ED25519 is an even newer option, introduced by openssh 6.5. It is a variant of the ECDSA algorithm but it solves the random number generator problem and uses a "nothing up my sleeve" curve. It will probably be the best option in the long term but right now there are still supported systems out there that don't have sufficiently new openssh.

So IMO that makes RSA (with a 2048 or 4096 bit key depending on how paranoid you are) still the most reasonable choice for general use.

Edit: update to current situation as of March 2017.

2
  • 12
    ECDSA has the same weakness as DSA in this respect. And in OpenSSH it's doubly fishy because OpenSSH only implements NIST curves that are suspected to be backdoored by the NSA. More info here: security.stackexchange.com/a/46781/15087
    – Shnatsel
    Dec 27, 2013 at 21:35
  • One mitigation for creating signatures without a good source of randomness is RFC 6979 [Deterministic Usage of the Digital Signature Algorithm (DSA) and Elliptic Curve Digital Signature Algorithm (ECDSA)]. I don't know if OpenSSH uses that though. Aug 20, 2019 at 16:41
11

Use RSA. Not for security reasons, but for compatibility reasons.

I don't recommend using DSA keys. As of OpenSSH 7.0, SSH no longer supports DSA keys by default. As the release notes for OpenSSH 7.0 say, "Support for ssh-dss host and user keys is disabled by default at run-time". Therefore, using DSA keys (ssh-dss) is just going to cause headaches.

ECDSA keys could be better, but sadly, ECDSA keys can also cause compatibility headaches on some platforms. On Fedora, gnome-keyring-daemon doesn't automatically pick up ECDSA SSH keys, so you won't be automatically prompted for a password to unlock your SSH key when you try to use it on Fedora.

RSA keys are completely free of these compatibility headaches. They're the most widely used, and so seem to be the best supported. Therefore, I recommend you generate RSA keys, to save yourself from annoyances later down the road.


As an editorial note, OpenSSH's decision to disable DSA support is a bit puzzling: 1024-bit DSA keys have approximately the same security as 1024-bit RSA keys, so it's not clear why OpenSSH disabled support for 1024-bit DSA keys but retain support for 1024-bit RSA keys. (OpenSSH still supports RSA; it has a special check to disable RSA keys that are 768 bits or shorter, but for DSA, it just disables all DSA keys, regardless of length.) Also, OpenSSH used to support DSA keys that are longer than 1024 bits in length; it's not clear why support for them has been disabled. Oh well, so it goes.

2
10

DSA and ECDSA have fixed length keys, and they are US government standards meaning that they know more about the standards than the general public. RSA is better known and you can generate longer keys with it (default is 2048 as opposed to DSA's 1024 bit fixed length), so it is (arguably) better to use.

6
  • 1
    According to the ssh-keygen man page, you have three choices for ECDSA key lengths: For ECDSA keys, the -b flag determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other than these three values for ECDSA keys will fail.
    – jfmercer
    Nov 23, 2013 at 2:31
  • @jfmercer 521 or 512? Aug 6, 2014 at 18:01
  • 3
    @Anonymouse it's really 521. See also crypto.stackexchange.com/questions/2482/…
    – nodakai
    Aug 21, 2014 at 10:10
  • 1
    @Anonymouse See Why do the elliptic curves recommended by NIST use 521 bits rather than 512?. In short, P521 uses this prime because 2^521-1 is a mersenne prime. Oct 21, 2014 at 11:51
  • ssh-keygen can generate only 1024 for DSA, but can use 2048 genereated by OpenSSL (which also had better PBE until OpenSSH's 'new' format). Mar 24, 2017 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .