Guide

SSH keys on a VPS

Last updated: 15 November 2026

An SSH key is much harder to guess than a password, and it lets you turn password login off. Do the steps in this order to avoid locking yourself out. If you are logged in as root, leave out sudo.

Fast VPS from $7.99 a month

See Fast VPS plansHow ordering works

1. Create a key on your own computer

ssh-keygen -t ed25519 -C "my-laptop"

Accept the default file and set a passphrase. This creates a private key (id_ed25519, never share it) and a public key (id_ed25519.pub). Windows 10 and later has the same command in PowerShell.

2. Add the public key to the server

On Linux and macOS:

ssh-copy-id USER@YOUR-IP

On Windows PowerShell, which has no ssh-copy-id:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh USER@YOUR-IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"

Use your normal user if you created one (see the first-login guide), or root.

3. Test it in a second terminal

Keep your current session open and open a new terminal: ssh USER@YOUR-IP should log you in with the key (asking only for the key's passphrase). Do not go on until this works.

4. Turn off password login

  1. Edit /etc/ssh/sshd_config and set PasswordAuthentication no. If you use root directly, set PermitRootLogin prohibit-password; set PermitRootLogin no only if you have already logged in with the key as a normal user and sudo works for that user.
  2. Check for override files: grep -ri PasswordAuthentication /etc/ssh/sshd_config.d/. On some images a file there overrides the main file; if one sets yes, change it to no in that file.
  3. Test the configuration with sudo sshd -t, then reload: sudo systemctl reload ssh (Debian and Ubuntu) or sudo systemctl reload sshd (AlmaLinux and Rocky).
  4. Check the result: sudo sshd -T | grep -i passwordauthentication should say no. Then try a new login in a third terminal.

If you lock yourself out

Use the emergency console (VNC) on your service page, if it shows one, log in there and undo the change. The first-login guide explains how to connect to it.

Related

Firewall with ufw · Docker on a VPS · Fast VPS

Questions and answers

How do I create an SSH key?
Run ssh-keygen -t ed25519 on your own computer, accept the default file and set a passphrase; share only the .pub file.

How do I add my key to the server?
Use ssh-copy-id USER@YOUR-IP on Linux or macOS; on Windows PowerShell pipe the public key into authorized_keys over ssh.

How do I avoid locking myself out?
Test key login in a second terminal before changing anything, keep the first session open, and use the emergency VNC console if something goes wrong.

Why is password login still on after I changed sshd_config?
A file in /etc/ssh/sshd_config.d/ can override it. Check with sshd -T and fix the override file.

Ready to try it? Fast VPS from $7.99 a month

See Fast VPS plansHow ordering works