Password guessing is automated, patient and free for the attacker. Key login replaces the guessable secret with a file that never travels the network. This guide sets it up and closes the password door behind you - without locking yourself out.
Your server proves who it is with a host key; keys let it demand the same proof from you. The client keeps a private key that never leaves its machine, the server keeps the matching public key, and login becomes a mathematical handshake instead of a typed secret. The delicate part is the order of operations: keys first, tested second, password door closed last.
On the computer you will connect from, run ssh-keygen -t ed25519 and accept the default location. Set a passphrase on the private key when asked - it is the lock on the key itself.
Two files appear: id_ed25519 is the private key and stays secret on this machine forever. id_ed25519.pub is the public half and is the only part that ever travels.
Windows users can run the same command in PowerShell, since modern Windows ships an OpenSSH client, or generate the key inside PuTTYgen if they live in WinSCP - the Windows connection guide in this series covers that side.
ssh-copy-id [email protected] appends your public key to the server account's ~/.ssh/authorized_keys file, with the right permissions set for you. Type the account password one last time to authorise it.
If you must do it by hand, the permissions are the step everyone gets wrong: the .ssh folder must be chmod 700 and authorized_keys must be chmod 600, both owned by the user. SSH silently ignores a key file that other users can read or write - silent, with no error message, which is why this deserves its own paragraph.
Open a second terminal or client window and log in. You should land inside without a password prompt for the account (your key passphrase is a different, local prompt - that one is fine).
Keep the first session open the whole time. It is your ladder back in if anything in the next step disagrees with your server. Every lockout story in IT begins with someone closing the working session too early.
Now edit /etc/ssh/sshd_config on the server and set:
PasswordAuthentication noPubkeyAuthentication yes (it is on by default, but confirm it)/etc/ssh/sshd_config.d/ can override the main file, which is a common reason the change seems ignored on cloud imagessudo systemctl restart ssh from your still-open sessionThe honest trade-off, stated plainly: whoever loses the only private key loses access. There is no password fallback to rescue you by design. Keep a backup of the key in a safe place, and give a second admin their own key rather than sharing yours - two keys, two names in the log.
See the whole Ubuntu SFTP setup done live, with the exact clicks and commands, in the Technical Anshu video.
Watch Full VideoRealistically, no. A password has a human-sized number of possibilities and machines try millions. A modern key's possibilities are astronomically larger, and the private half is never sent over the network to be captured.
From the network, yes - that is the point of the setting. Recovery means physical or console access to the server, or another admin account whose key still works. This is why a backup key copy and a second admin key are part of the setup, not extras.
Yes. One key per person means the logs name a person, and removing one person's access is deleting one line from authorized_keys instead of changing a shared password everywhere.