16 November 2026 · One command a day
How do I create an SSH key pair on Linux with ssh-keygen?
ssh-keygen creates an SSH key pair. That is two files: a private key that stays on your computer and a public key that you put on your server. You use it when you set up a new VPS, so you can log in with a key instead of a password, and so that password logins can later be switched off.
I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.
The command
ssh-keygen -t ed25519 -C "user@host"
Run this on your own computer, not on the server. ssh-keygen is the key tool that comes with OpenSSH. -t ed25519 sets the key type. Ed25519 keys are short, fast and secure, and every current version of Ubuntu supports them. -C "user@host" adds a comment to the public key. The comment does not change how the key works. It is a label that helps you tell keys apart later in the server's authorized_keys file. You do not need sudo, because the key belongs to your own user.
What you will see
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_ed25519
Your public key has been saved in /home/user/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:k3Vq9XcR2pLm7TzA8bWn1yHs5uJd4eFo6gQiC0vKxYw user@host
The key's randomart image is:
+--[ED25519 256]--+
| .o+=*o. |
| . o+B.o |
| o.=.= |
| . =.+ . |
| S.o.o |
| . +=o . |
| o.=E+ |
| . +*=.o |
| o=*B+ |
+----[SHA256]-----+
Press Enter at the first prompt to save the key in the default place. Then type a passphrase twice. The characters will not show as you type. After that you have two files. id_ed25519 is the private key. id_ed25519.pub is the public key, a single line of text that starts with ssh-ed25519. The fingerprint is a short summary of the key, so you can check later that a server holds the right one. You can ignore the randomart picture.
When to use it
- You have just bought a VPS and want to log in with a key before you turn off password logins.
- You have a new laptop and need its own key, rather than copying the old private key across.
- A deploy tool or git host needs a public key so it can connect to your server or pull a repository.
Watch out for
Only ever share the file that ends in .pub. The private key, id_ed25519 with no extension, should never leave your machine, be pasted into a chat or be committed to a repository. Anyone who has it can log in as you. Also take care if ssh-keygen asks Overwrite (y/n)?. That means a key already exists at that path, and saying yes destroys it, along with your access to every server that trusts it. Say no and pick a new file name with -f ~/.ssh/id_ed25519_new instead.
Questions people ask
Should I set a passphrase?
Yes, for a key you use yourself. It protects the key if your laptop is lost, and ssh-agent means you only type it once per session. Keys used by unattended scripts often have no passphrase, so lock those down in other ways.
How do I put the public key on my server?
Run ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host. It adds the key to ~/.ssh/authorized_keys on the server and sets the right permissions. You can also copy the file across with scp and append it yourself.
Key-based logins, and the freedom to switch off passwords altogether, are the kind of control you only get on a server you run yourself. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.
Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.
Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.
Affiliate link.