Key takeaways
- SSH keys are far stronger than passwords and can't be guessed.
- Keep the private key on your computer; only the public key goes on the server.
- Test key login in a second window before disabling passwords.
1. Create a key pair on your computer
macOS, Linux and Windows 10/11 (PowerShell) all include OpenSSH:
ssh-keygen -t ed25519 -C "you@example.com"
Press Enter to accept the default location and set a passphrase. This creates ~/.ssh/id_ed25519 (private — never share) and ~/.ssh/id_ed25519.pub (public).
2. Copy the public key to the server
On macOS and Linux:
ssh-copy-id deploy@203.0.113.10
On Windows, paste the contents of id_ed25519.pub into the server’s ~/.ssh/authorized_keys:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys # paste, save
chmod 600 ~/.ssh/authorized_keys
3. Test
Open a new terminal and run ssh deploy@203.0.113.10. You should be asked for the key’s passphrase, not the account password.
4. Disable password login
Keep your working session open, then edit /etc/ssh/sshd_config (or a file in /etc/ssh/sshd_config.d/):
PasswordAuthentication no
PermitRootLogin no
Apply with sudo systemctl reload ssh and test again in a new window before closing the old one.
Frequently asked questions
Which key type should I use?
Ed25519. It's modern, fast and supported by all current OpenSSH versions. Use RSA 4096 only for very old systems.
What if I lose my private key?
You'll need another way in — your provider's web console or rescue mode — to add a new public key. Keep a secure backup of your key.