Sub topic 3
Choosing a Key Type
Prerequisites and the decision
This chapter assumes you can use a Linux or macOS command line, connect to a remote Linux server with ssh, and understand basic Unix file permissions. You should also know where your home directory and .ssh directory are located.
SSH public key authentication uses two related files:
- The private key stays on your client computer. It proves that you own the identity.
- The public key is copied to the server. It lets the server verify a signature made by the private key.
The key type determines the cryptographic algorithm used by this pair. Choose a type that your OpenSSH client, server, operating system, and organization all support.
Ed25519 is the usual default
For a new personal or administrative SSH key, Ed25519 is usually the best choice. Ed25519 is a modern public-key algorithm based on elliptic-curve cryptography. It provides strong security with small keys and fast operations.
Generate one with:
ssh-keygen -t ed25519 -C "alice@laptop" -f ~/.ssh/id_ed25519The comment helps you identify the key later. It does not affect authentication. The command creates:
~/.ssh/id_ed25519, the private key~/.ssh/id_ed25519.pub, the public key
Protect the private key with a passphrase when prompted. A passphrase does not change the key type. It encrypts the private key file so that someone who copies the file cannot immediately use it.
When RSA still makes sense
RSA is an older algorithm that remains widely supported. Use it when you must connect to an old SSH server, embedded device, appliance, or managed service that does not accept Ed25519.
Use at least 3072 bits for a new RSA key. A 4096-bit key offers a larger margin but takes more space and may be slightly slower.
ssh-keygen -t rsa -b 4096 -C "alice@legacy-server" -f ~/.ssh/id_rsa_legacyDo not replace an existing working key just because it uses RSA. A gradual migration is safer. Create an Ed25519 key, install its public key, test it, and remove the old key only after you confirm that every required system works.
Other key types and compatibility
ECDSA keys are supported by many OpenSSH installations, but Ed25519 is generally simpler to choose for new keys. DSA keys are obsolete and disabled by current OpenSSH versions. Do not create new DSA keys.
Hardware-backed FIDO2 keys, such as ed25519-sk, can keep the private operation inside a security key. They can provide stronger protection against theft, but they require compatible hardware and client support. They are a separate choice from a normal file-based Ed25519 key.
| Key type | Best use | Main limitation |
|---|---|---|
| Ed25519 | New servers and normal user accounts | Very old systems may not support it |
| RSA 3072 or 4096 | Legacy compatibility | Larger and older design |
| ECDSA | Existing organizational requirements | Usually no reason to prefer it for new keys |
| DSA | None for new deployments | Obsolete and disabled |
Make a deliberate choice
Check the client and server versions before choosing a key for a mixed or legacy environment:
ssh -V
ssh [email protected] 'sshd -V 2>&1 || true'The second command may print the server version through standard error, and some systems restrict this check. If you cannot verify support, try Ed25519 on a test account or use RSA for that specific legacy host.
Keep separate keys for different trust boundaries. For example, use one key for personal servers and another for an employer’s infrastructure. If one key is lost or exposed, you can revoke it without affecting unrelated systems.
Exercise
You administer a current Linux server and a ten-year-old network appliance. Which key types should you consider, and why?
Show answer
Use Ed25519 for the current Linux server. Consider RSA with at least 3072 bits for the appliance if it does not support Ed25519. Test compatibility before changing an existing login method.