01
How an SSH key works
An SSH key is a pair of files created together:
- the private key (for example
id_ed25519) stays on your computer. It is as valuable as a password: never send it, do not copy it to a server;
- the public key (
id_ed25519.pub) goes on the servers. It can be shown safely: it is only used to check that you hold the private key.
When you connect, the server checks that your computer has the private key matching an authorized public key. No password travels over the network, and a key cannot be guessed the way a password can. That is why, once the key is in place, you end up turning off passwords.
The recommended type today is Ed25519: it is also the type ssh-keygen creates by default in recent versions of OpenSSH. If you do not know how to connect to your VPS yet, start with connecting to your VPS over SSH.
02
Create the key on your computer
The command is the same in a Mac or Linux Terminal and in PowerShell on Windows 10 or 11:
ssh-keygen -t ed25519 -C "mon-ordinateur"
-t ed25519 chooses the key type;
-C adds a comment, useful to recognize the key later on the server (the computer's name, for example).
Press Enter to accept the suggested location: ~/.ssh/id_ed25519 on Mac and Linux, C:\Users\votre-nom\.ssh\id_ed25519 on Windows. If a key already exists there, answer n: otherwise it would be replaced, and the servers that accept it would turn you away.
Then choose a passphrase. It encrypts the private key on your disk: if your computer is stolen, the key stays unusable. As with a password, nothing is shown while you type.
You get two files, the private key and the public key ending in .pub. To display the key's fingerprint and recognize it later:
ssh-keygen -lf ~/.ssh/id_ed25519.pub
With PuTTY, the private key must be in .ppk format. In PuTTYgen, which comes with PuTTY, the Conversions menu, Import key, opens an OpenSSH key, which you then save with Save private key. PuTTYgen can also create a key (type EdDSA, Ed25519): the public key to add on the server is then the text in the Public key for pasting into OpenSSH authorized_keys file box.
03
Add the public key to the VPS
On Mac and Linux, ssh-copy-id does everything in one command. It logs in one last time with the password, then appends the public key to the account's ~/.ssh/authorized_keys file, creating the folder and the file if needed:
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@203.0.113.10
Replace root with your user if you have created one, and add -p 2222 if the server listens on another port. Each account has its own file: a key added for root does not work for alice.
On Windows, ssh-copy-id does not exist. Display the public key in PowerShell and copy the whole line, which starts with ssh-ed25519:
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub
Then log in to the VPS with the password, under the account concerned, and paste the key at the end of the file, on a single line:
mkdir -p ~/.ssh
nano ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
In nano, save with Ctrl+O then Enter, and quit with Ctrl+X. The two chmod commands set the permissions: 700 for the folder, 600 for the file, readable by their owner only. By default, the SSH server checks these permissions (the StrictModes setting) and ignores the keys in a file that is too open. If you created the file as root for another account, give it back to its owner: chown -R alice:alice /home/alice/.ssh.
04
Test, then turn off passwords
Test first, in a new window, without closing the open session:
ssh root@203.0.113.10
The server should no longer ask for the account's password, only for the key's passphrase if you set one. If it still asks, check the permissions and the content of authorized_keys, and run ssh -v to see which key is offered.
Only then, turn off passwords. On Debian and Ubuntu, the main file /etc/ssh/sshd_config reads the files in the /etc/ssh/sshd_config.d/ folder. Create your own there:
sudo nano /etc/ssh/sshd_config.d/00-cles.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
For each setting, the SSH server keeps the first value it reads: the name starts with 00 so it comes before any file shipped with the system that would turn passwords back on. Check the syntax, apply, then check the value actually in use:
sudo sshd -t
sudo systemctl restart ssh
sudo sshd -T | grep -i passwordauthentication
The restart does not close your open session. Test a new connection in another window before closing anything. If you are locked out, the console in the customer area lets you delete the file and restart SSH. The guide securing a Linux VPS completes this setting: a sudo account, no direct root login, firewall and fail2ban.
05
Passphrase, SSH agent and several computers
The SSH agent keeps the unlocked key in memory: you type the passphrase once instead of at every connection.
- On Mac and most Linux desktops, an agent already runs with your session. Add the key to it with
ssh-add ~/.ssh/id_ed25519.
- On Windows, the
ssh-agent service is disabled by default. In a PowerShell window opened as administrator, set it to automatic and start it, then add the key in a normal PowerShell window:
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
With PuTTY, the agent is called Pageant and loads .ppk keys.
To change the passphrase without changing the key: ssh-keygen -p -f ~/.ssh/id_ed25519.
Several computers: create one key per computer rather than copying the same one everywhere, and add each public key on its own line in authorized_keys. If a computer is lost or stolen, delete its line: the others keep working. Back up your private keys somewhere safe: a lost key cannot be recovered, you have to create another one and add it from the console.
To use a key other than the default one, specify it with ssh -i, or in the ~/.ssh/config file with an IdentityFile line. The same key also works to send files over SFTP.
06
On CloudFive
On the Ryzen VPS, from €5.99 per month, you have root access: you add your keys and set up SSH as you see fit. If a configuration mistake locks you out, the console in the customer area manager.cloudfive.fr gives you control back without going through SSH, and a snapshot taken before the changes lets you roll back.
Our VPS run on AMD Ryzen 9 9950X with DDR5 memory and NVMe storage, or on Intel Xeon, as LXC containers or KVM virtual machines. Each has a dedicated IPv4 address and basic anti-DDoS protection included. The servers are in France, monthly with no commitment, with support in French 7 days a week. To pick a plan, see choosing the right VPS.
07
Frequently asked questions
How do I create an SSH key?
Run ssh-keygen -t ed25519 in the Terminal on Mac and Linux, or in PowerShell on Windows 10 and 11. Accept the suggested location and choose a passphrase. You get a private key, to keep, and a public key ending in .pub, to add on the server.
How do I copy my SSH key to a VPS from Windows?
ssh-copy-id does not exist on Windows. Display the public key with Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub, copy the line, then paste it on the VPS at the end of the ~/.ssh/authorized_keys file of the account concerned. Then set the permissions with chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys.
Why does the server still ask for the password?
Most often, the permissions of the .ssh folder or the authorized_keys file are too open, the key was added for another account, or it is split over several lines. Check these three points and run ssh -v to see which key your computer offers.
How do I turn off SSH password login?
Once key-based login has been tested, create a file in /etc/ssh/sshd_config.d/ with PasswordAuthentication no and KbdInteractiveAuthentication no. Check with sudo sshd -t, restart with sudo systemctl restart ssh, and test in a new window while keeping your session open.
Should I put a passphrase on my SSH key?
It is recommended: it encrypts the private key, which stays unusable if your computer is stolen. To avoid retyping it at every connection, load the key into the SSH agent with ssh-add.