Create and Check an Ed25519 SSH Key with ssh-keygen

Every SSH setup starts the same way: ssh-keygen makes a key pair, and everything else builds on getting that first step right. You will create a new Ed25519 key, protect the private half with a passphrase, record its fingerprint, and check the public half actually matches it. Allow about ten minutes. You need a Linux shell with the openssh-client package installed and a destination account to keep the key in. The examples use an unprivileged user account; sudo is never required.

1. Check the installed command

This guide describes the OpenSSH client installed on this machine, package version 1:9.6p1-3ubuntu13.19. The local ssh-keygen(1) page lists Ed25519, RSA, ECDSA and FIDO-backed key types, and Ed25519 is the sensible default for a new ordinary identity: fixed length, no bit-size decision to get wrong.

$ command -v ssh-keygen
/usr/bin/ssh-keygen
$ dpkg-query -W -f='${Package} ${Version}\n' openssh-client
openssh-client 1:9.6p1-3ubuntu13.19

Second command says the package is missing? Install OpenSSH through your normal distribution process before continuing. Never copy a private key from an unknown source just to skip the install.

2. Choose a new output path

Keep private keys in ~/.ssh, and pick a filename that does not already hold a key you need. The example below uses id_ed25519_work; swap [email protected] for a comment that actually helps you identify the key later. The comment is descriptive metadata, not a password.

$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$ test ! -e ~/.ssh/id_ed25519_work && echo 'output path is unused'
output path is unused

That test is the checkpoint. Prints nothing? Stop and pick another filename. A later ssh-keygen prompt can offer to overwrite the file, and accepting it destroys the existing private key at that path, which can lock you out of anything that trusts it.

3. Generate the key pair

This creates a private key at the path given by -f and a public key beside it with .pub appended. -t ed25519 selects the key type. It asks for a passphrase twice, and nothing is displayed while you type it.

$ ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_work -C "[email protected]"
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/you/.ssh/id_ed25519_work
Your public key has been saved in /home/you/.ssh/id_ed25519_work.pub

Use a unique passphrase you can retrieve from your password manager. The private key is encrypted once a passphrase is set, and there is no recovery mechanism for a forgotten one: you would need to generate another key and get its public half trusted all over again. An empty passphrase is a deliberate trade-off, not a harmless default.

Check the resulting files and their modes:

$ ls -l ~/.ssh/id_ed25519_work ~/.ssh/id_ed25519_work.pub
-rw------- 1 you you 411 Sep 27 04:03 /home/you/.ssh/id_ed25519_work
-rw-r--r-- 1 you you 103 Sep 27 04:03 /home/you/.ssh/id_ed25519_work.pub
$ ssh-keygen -y -f ~/.ssh/id_ed25519_work > /tmp/id_ed25519_work.pub
$ cmp ~/.ssh/id_ed25519_work.pub /tmp/id_ed25519_work.pub && echo 'public key matches private key'
public key matches private key

Your file sizes and timestamps will differ. The private key should be readable only by you; the public key is meant to be shared, the private key and its passphrase are not. That temporary file is safe for the comparison because it only ever holds the public key, so delete it once you are done checking.

4. Record the fingerprint

A fingerprint is a short identifier for a public key. Compare it through a trusted channel whenever someone asks you to confirm which key you supplied. This installed command uses SHA-256 by default.

$ ssh-keygen -lf ~/.ssh/id_ed25519_work.pub
256 SHA256:6v9ygDgUClo0WkRNABKO/Hyy7LclwWl9QVxDfTDEJc8 [email protected] (ED25519)

Every generated key is different, so your fingerprint will not match the one above. What matters is the shape: a bit count, a SHA256: value, the comment, and the key type. Need the older MD5 display for a specific legacy process? Request it explicitly with -E md5, and do not mistake that display choice for any change to the key itself.

5. Use only the public key on a server

When an administrator or service asks for your SSH key, hand over the single line from the .pub file, which normally starts with ssh-ed25519. Never send the file without .pub, paste the private key into a ticket, or upload it anywhere to make authentication work. The server-side administrator places your public line in the target account's authorised keys configuration.

$ cat ~/.ssh/id_ed25519_work.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... [email protected]

Confirm the fingerprint with whoever installed a newly added key before relying on it. Server rejects the key? First check the public line was copied as one unchanged line and installed for the right account. Never disable host-key checking or make the private key world-readable as a troubleshooting shortcut.

6. Change the passphrase later

You can change the passphrase without regenerating the key pair. It asks for the private-key filename, the old passphrase, then the new one twice. This rewrites the private key, so back it up first if the key is valuable and you have somewhere safe to keep that backup.

$ cp --preserve=mode,timestamps ~/.ssh/id_ed25519_work ~/.ssh/id_ed25519_work.backup
$ ssh-keygen -p -f ~/.ssh/id_ed25519_work
Enter old passphrase:
Key has comment '[email protected]'
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.

Test the new passphrase, then keep that backup only if you have a clear reason to, protected exactly like the original. Deleting it later is irreversible. Lost the old passphrase entirely? ssh-keygen -p cannot bypass it: generate a different key and update the trusted public-key list instead.

Common traps

Done means