Creating SSH keys for server logins
A key pair replaces the root password with something that cannot be guessed. Create it once on your own computer and every server you rent can use it.
What is an SSH key pair?
Two linked files: a private key that never leaves your computer and a public key you hand to servers. When you connect, the server checks that you hold the private half without it ever crossing the network. Guessing an Ed25519 private key is not practical, which is why key-only login ends the password-guessing traffic every public server receives.
How do I create a key on macOS or Linux?
Open a terminal and run ssh-keygen with the Ed25519 type. Accept the default file name unless you already have a key there, and set a passphrase when asked.
ssh-keygen -t ed25519 -a 64 -f ~/.ssh/id_ed25519 -C "$(whoami)@$(hostname -s)" # Your identification has been saved in /home/you/.ssh/id_ed25519 # Your public key has been saved in /home/you/.ssh/id_ed25519.pub head -n 1 ~/.ssh/id_ed25519.pub
The -a 64 option makes the passphrase harder to brute-force if the file is ever stolen, and the comment helps you recognise the key later in a list. The line printed by head, starting with ssh-ed25519, is what you paste into our account.
And on Windows?
Windows 10 and 11 include OpenSSH, so the same command works in PowerShell. The files land in C:\Users\you\.ssh\. If you prefer PuTTY, generate an Ed25519 key in PuTTYgen, save the private key as a .ppk file, and copy the text from the box labelled for OpenSSH authorized keys.
ssh-keygen -t ed25519 -C "workstation" type $HOME\.ssh\id_ed25519.pub
Should I still use RSA keys?
Only when an old client or device cannot handle Ed25519. Ed25519 keys are short, fast and secure by design. If you need RSA, choose 4096 bits; current OpenSSH versions refuse the old SHA-1 signature scheme, so very old clients may fail even with a valid RSA key.
| Type | Command | When to choose it |
|---|---|---|
| Ed25519 | ssh-keygen -t ed25519 | Default for every modern client |
| RSA 4096 | ssh-keygen -t rsa -b 4096 | Legacy tools that lack Ed25519 |
| Ed25519 on a hardware token | ssh-keygen -t ed25519-sk | When the private key must live on a security key |
How do I get the key onto a new server?
Add it to your account before you order. In the account area, open SSH keys and paste the public key line. When you configure a server, tick the keys to install: the machine is delivered with them in root's authorized_keys and no root password is sent at all. The same keys can be chosen again for a console reinstall, so a rebuilt server is reachable with the same login.
ssh -i ~/.ssh/id_ed25519 root@192.0.2.40
How do I add a key to a server that is already running?
Append the public key to the target user's ~/.ssh/authorized_keys. From a machine that can already log in, ssh-copy-id does this with the right permissions in one step:
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@192.0.2.40
By hand, the folder must be mode 700 and the file mode 600, both owned by the user, or the SSH service silently ignores them.
install -d -m 700 -o admin -g admin /home/admin/.ssh printf '%s\n' "ssh-ed25519 AAAAC3Nz...k9 colleague-mac" >> /home/admin/.ssh/authorized_keys chown admin:admin /home/admin/.ssh/authorized_keys && chmod 600 /home/admin/.ssh/authorized_keys
How do I avoid typing the passphrase all day?
Load the key into an agent once per session. On macOS, ssh-add --apple-use-keychain stores the passphrase in the keychain; on Linux the desktop usually runs an agent already; on Windows, enable the OpenSSH Authentication Agent service. A short entry in ~/.ssh/config then saves typing the address and user:
Host fra-db
HostName 192.0.2.40
User admin
IdentitiesOnly yes
IdentityFile %d/.ssh/id_ed25519
My private key is gone. What now?
Use the rescue system to add a new public key to the server; the Recover lost SSH access guide walks through it. Then remove the lost key's line from every authorized_keys file and from your account. Keeping a second key on another device, also listed on each server, turns a lost laptop into a minor inconvenience rather than a lockout.
Related pages
Recover lost SSH access
Lost your private key or locked yourself out with a bad SSH setting? Add a new key or fix the configuration from rescue mode.
Read moreChange the root password
Set a new root password on a running server, or reset a forgotten one from the rescue system, and decide whether root needs a password at all.
Read moreTransfer files with SFTP
Upload and download files over SSH with sftp, scp or a graphical client, and give outside users a locked upload folder.
Read moreHardening a new dedicated server
The first hour on a fresh machine: SSH keys, a firewall, automatic updates, brute force blocking and a habit of checking what listens.
Read moreQuestions and answers
Is Ed25519 or RSA the better key type?
Ed25519 suits every current client. Keep RSA at 4096 bits for legacy software that predates Ed25519 support.
Will I get a root password if I choose an SSH key?
No. A server ordered with keys is delivered with those keys for root and no root password. You can set one later with passwd.
Can I install the same key on many servers?
Yes. The public key is safe to share; one key pair can open every server you rent. Use a separate key per device so one can be revoked alone.
Why is my key ignored by the server?
Check permissions: the .ssh folder must be 700 and authorized_keys 600, both owned by the login user. Also make sure the whole key is on a single line.
Do I need a passphrase on the key?
It is strongly advised. A passphrase protects the private key if the file is copied, and an SSH agent means you type it only once per session.