Key types and formats
Ed25519, ECDSA and RSA keys, security keys, and the file formats you might be handed.
An SSH key pair has a private key (secret) and a public key (shared). You put the public key on the host. The private key proves it is you.
Types
- Ed25519. Small, fast and safe. The best choice for new keys. Public keys start with
ssh-ed25519. See RFC 8709. - ECDSA. Uses NIST curves
nistp256,nistp384andnistp521(RFC 5656). Public keys start withecdsa-sha2-nistp256and so on. - RSA. The oldest type, accepted almost everywhere. Use 3072 bits or more. Newer hosts accept only SHA-2 signatures (
rsa-sha2-256,rsa-sha2-512, RFC 8332) and refuse the oldssh-rsa(SHA-1) signature. - DSA (
ssh-dss). Obsolete and switched off in current OpenSSH. Replace it. - Security keys (FIDO2),
[email protected]and[email protected]. The private key lives in a hardware key. See Security keys.
File formats
- OpenSSH private key. Starts with
-----BEGIN OPENSSH PRIVATE KEY-----. The formatssh-keygenwrites today. It can be protected with a passphrase. - Traditional PEM. Starts with
-----BEGIN RSA PRIVATE KEY-----(orEC PRIVATE KEY). Older, still common. - PKCS#8. Starts with
-----BEGIN PRIVATE KEY-----. - PuTTY
.ppk. The PuTTY format. Convert it to OpenSSH format withputtygen:puttygen key.ppk -O private-openssh -o key. See Convert a PuTTY .ppk key to OpenSSH format, and PPK version 3. - Public key line. One line:
ssh-ed25519 AAAA... comment. This goes inauthorized_keys. - RFC 4716 public key. A multi-line
---- BEGIN SSH2 PUBLIC KEY ----file.ssh-keygen -i -fconverts it.
If ssh says Load key "...": invalid format, see SSH Load key "invalid format" and "error in libcrypto".
Making a key
ssh-keygen -t ed25519 -C "me@laptop"
You are asked for a passphrase. Use one: it protects the file if the device is lost. To change or remove it later, see Change or remove an SSH key passphrase with ssh-keygen -p. The files are ~/.ssh/id_ed25519 (private) and ~/.ssh/id_ed25519.pub (public).
Safe handling
- Never send the private key. Only the
.pubfile is shared. - Give each device its own key. Remove a lost device's public key from the hosts.
- Check
authorized_keysnow and then and remove keys you do not recognize.