SSH Keys and Key Pairs Explained: Which Type to Pick
Developer · Published October 18, 2026 · Updated October 24, 2026 · 4 min read
Written by Akinrinmade Michael
A key pair is two linked keys. What one locks, only the other can open. Developers use them to sign in to servers over SSH, to sign code and to set up encrypted connections. SSH keys are popular because they're both safer and more convenient than a password.
Public and private
- The public key can be shared with anyone. You put it on a server or a service like GitHub.
- The private key stays with you and is never shared. It proves who you are.
- When you connect, the server sends a challenge that only the matching private key can answer. Your private key never leaves your computer.
What happens when you connect
- You run
ssh user@server. Your computer offers a public key. - The server checks whether that key is in the user's authorized_keys file.
- If it is, the server sends a random challenge.
- Your computer signs the challenge with the private key and sends it back.
- The server checks the signature with the public key. If it's valid, you're in, and no password was sent.
Because nothing secret travels over the network, someone who records the whole conversation learns nothing they can reuse. That's a big difference from a password.
Which type to choose
| Type | Key size | Notes |
|---|---|---|
| Ed25519 | Short, fixed | Small, fast and modern. The best choice for new SSH keys if the server supports it, and nearly all do now |
| RSA | 3072 bits or more | Older and supported everywhere. Use 3072 or more for new keys, and 2048 only if you must |
| ECDSA P-256 | Short | Small keys, widely supported, though harder to implement safely than Ed25519 |
The Key Pair Generator makes all of these in your browser. For Ed25519 it saves the private key in OpenSSH's own file format, and for the others in PKCS#8. We tested each file type with OpenSSH to make sure it's accepted.
Using the keys
- Save the private key as id_ed25519 (or the name for your type) in the hidden .ssh folder in your home folder.
- On Mac and Linux, run chmod 600 on it so only you can read it. SSH refuses keys that other users can read.
- Add the public key line to the server's authorized_keys file, or paste it into the service's settings page.
- Connect with ssh as usual. No password is needed.
Setting up a code host
For GitHub, GitLab and similar services, open the SSH keys page in your account settings, choose to add a key, paste the whole public key line, and give it a name such as work laptop. Then test with ssh -T git@github.com or the equivalent for your host. If you see a greeting with your username, it works. Use the SSH address of a repository, not the web address, so Git uses your key.
A passphrase and the agent
A passphrase encrypts the private key file, so a stolen laptop or a copied file isn't enough to log in as you. The cost is typing it each time. An SSH agent solves that: you open the key once per session and the agent holds it in memory for later connections. Operating system key chains can store the passphrase for you.
What the odd text is
Keys are binary data written as text, so they look like long strings of letters. Both the PEM format and the SSH public key line use Base64. You can see how that encoding works with the Base64 Encoder. The fingerprint shown is a SHA-256 hash of the public key, a short way to check that two people are looking at the same key. See the Hash Generator for more on hashes.
Fixing common errors
- Permission denied (publickey). The server doesn't have your public key, or you're offering a different key. Check the authorized_keys file and try
ssh -vto see which keys are offered. - Unprotected private key file. The file's permissions are too open. Run chmod 600 on it.
- Host key changed warning. The server's own identity changed, which can be a rebuilt server or a problem worth taking seriously. Check with the server's owner before you remove the old entry.
- Wrong user name. The key may be right and the account wrong. Cloud servers often use names like ubuntu or ec2-user.
Be careful with private keys
Anyone with your private key can act as you. Don't email it, paste it into chats or commit it to a code repository. Use a separate key for each device, so a lost laptop means removing one key and not all of them. For keys that protect something valuable, make them on your own computer with ssh-keygen and add a passphrase. If a private key is ever exposed, treat it as compromised: make a new pair and remove the old public key everywhere it was installed.