Security guide
How to Set Up SSH Keys and Turn Off Password Logins
Short answer
Run ssh-keygen -t ed25519 on your own computer, copy the public key to the server's ~/.ssh/authorized_keys, check you can log in with it, then set PasswordAuthentication no in a file under /etc/ssh/sshd_config.d/ and restart SSH.
An SSH key pair has two halves. The private key stays on your computer; the public key goes on the server. Bots guessing passwords get nowhere against a server that only accepts keys. Windows 10 and 11, macOS and Linux all include the OpenSSH tools used below, so there's nothing to install.
Create the key
Open PowerShell on Windows, or Terminal on macOS and Linux, and run:
ssh-keygen -t ed25519 -C "your-name-laptop"Press Enter to accept the default location, then set a passphrase. It protects the key if your laptop is lost or stolen, and with an agent (below) you type it once per session. You now have two files in the .ssh folder in your home folder:
id_ed25519is the private key. Never copy it anywhere or send it to anyone.id_ed25519.pubis the public key, which goes on servers.
Ed25519 keys are short, fast and supported by every current version of OpenSSH. Use -t rsa -b 4096 only if you need to log in to a very old system.
Copy the public key to the server
On macOS and Linux:
ssh-copy-id user@your-vps-ipWindows doesn't have ssh-copy-id, so send the key across in PowerShell:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@your-vps-ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"Both ask for the account's password one last time.
Test the key
ssh user@your-vps-ipYou should get in without the account password (you'll be asked for the key's passphrase instead, if you set one). Keep this session open during the next step, so you have a way back in if something goes wrong.
Turn off password logins
Create a new settings file rather than editing the main one:
sudo nano /etc/ssh/sshd_config.d/00-hardening.confPasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-passwordSSH uses the first value it reads for each setting, and reads the files in sshd_config.d in name order. Cloud images often include 50-cloud-init.conf with PasswordAuthentication yes, so starting your file's name with 00- makes sure your setting wins. prohibit-password lets root log in with a key only; if you log in as a normal user with sudo, use no.
Check the configuration, restart SSH, and confirm the settings it's using:
sudo sshd -t
sudo systemctl restart ssh
sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin'On AlmaLinux and Rocky the service is called sshd, so restart it with sudo systemctl restart sshd. Open a second terminal and log in again before you close the first one.
Stop typing the passphrase every time
An SSH agent holds the unlocked key for your session. On macOS, add this to ~/.ssh/config:
Host *
AddKeysToAgent yes
UseKeychain yesOn Windows, run PowerShell as administrator once to start the agent automatically, then add the key:
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519The same ~/.ssh/config file can give each server a short name, so ssh myvps replaces the full command:
Host myvps
HostName 203.0.113.50
User deploy
IdentityFile ~/.ssh/id_ed25519PuTTY and FileZilla
PuTTY uses its own key format. Open PuTTYgen, choose Conversions > Import key, load id_ed25519 and save it as a .ppk file. FileZilla can use the key for SFTP: add it under Edit > Settings > Connection > SFTP.
UK VPS hosting with full root access
Guaranteed AMD EPYC cores, SSD RAID storage and DDoS protection on every plan, from £5.99 a month with no VAT to add. Need faster cores? Upgrade to Ryzen.
See VPS plansQuestions
Can I use the same key on several servers?
Yes. Copy the same public key to each server. Use a separate key for each computer, so you can remove one device's access without touching the others.
What if I lose my private key?
It can't be recovered. Log in through your VPS's browser console, remove the old public key from ~/.ssh/authorized_keys, and add a new one.
Is Ed25519 better than RSA?
For new keys, yes. The keys are shorter and faster, and every current SSH server and client supports them. RSA 4096 still works if you need it for older systems.
Why does the server still ask for a password?
Usually the key isn't in ~/.ssh/authorized_keys for that user, or the permissions are too open: the .ssh folder should be 700 and authorized_keys 600, owned by the user. Run ssh -v to see which keys your client offers.
Related guides
Sources
Commands are for Ubuntu 24.04, Debian 12 and AlmaLinux 9, as of 16 October 2026. If something here no longer matches what you see, tell us and we'll update it.