The automated setup gave your server an SSH door so you can manage it from your desk. This page locks that door properly: key login in, password guessing out — done in the safe order that cannot lock you out of your own server.
SSH is the front door of almost every Linux server, and the internet knocks on it constantly. Automated bots try common passwords against exposed SSH servers within hours of them appearing. A password — even a decent one — is a single secret that can be guessed, leaked or reused. An SSH key is a matched pair: a private half that never leaves your computer and a public half that lives on the server. No key, no entry, and there is nothing to guess. Here is the whole hardening sequence, in the only safe order.
Run this on your machine, not the server. Accept the default location and set a passphrase on the key if the computer is shared.
ssh-keygen -t ed25519 creates a modern, strong key pair.pub public key (this half is safe to copy to servers)While password login still works, copy the public half across. On Linux and macOS the tool is built in; on Windows, the same command ships with the OpenSSH client, or you can paste the public key into the file by hand.
ssh-copy-id [email protected] — use your real username and server address~/.ssh/authorized_keys on the serverssh [email protected] — if no password is asked, the key worksThis is the step that separates a secure server from a locked-out admin. Open a new terminal window and log in with the key while your first session stays open. Only when the second login succeeds do you touch the settings. If anything is wrong, your first session is still there to fix it.
Edit the SSH server settings on the server with sudo nano /etc/ssh/sshd_config, set the two lines below, then restart the service with sudo systemctl restart ssh. Test in yet another new session before closing the old ones.
PasswordAuthentication no — passwords stop working for SSH; keys onlyPermitRootLogin prohibit-password — the root account cannot be reached with a password over SSH at all; you log in as yourself and use sudosudo is the safer and more accountable patternKeep one local way in that does not depend on SSH: the machine’s own screen and keyboard, the virtual machine console, or your hosting provider’s web console. Server rooms and VPS panels both offer one. As long as that exists, even a total SSH mistake is a five-minute fix, not a disaster.
The video’s server is reachable by SSH the moment setup ends. Do this hardening pass right after your first login, while the steps are fresh.
▶️ Watch Full VideoNo, as long as you still have the local console or provider web console. Log in there, add a new public key to ~/.ssh/authorized_keys, and remove the old one. This is why keeping a non-SSH way into the machine matters.
Yes. One key pair per person, used on every server they administer, is the normal pattern. If a laptop is ever lost, you remove that one public key from each server and the lost laptop’s access ends everywhere.
It reduces background noise in the logs but adds almost no real security — bots find open ports on any number. Keys plus password login off is the protection that matters. Change the port only if you enjoy quieter logs, and update your firewall rule to match.