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.
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.
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.
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.
/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.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.sudo sshd -t, then reload: sudo systemctl reload ssh (Debian and Ubuntu) or sudo systemctl reload sshd (AlmaLinux and Rocky).sudo sshd -T | grep -i passwordauthentication should say no. Then try a new login in a third terminal.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.
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.