Skip to main content
A key is a pair of files: the private one stays with you, the public one sits on the server. Unlike a password, a key practically cannot be brute-forced, and you type nothing at login.

Creating a key

  1. Key – in the terminal on your own computer:
    At the prompts:
    • Path – press Enter. Never share the private key ~/.ssh/id_ed25519, the public ~/.ssh/id_ed25519.pub goes on the server.
    • Passphrase – a password on the key itself, set one: a stolen file is useless without it. To avoid typing it every time: ssh-add ~/.ssh/id_ed25519.
  2. Key to the server – replace IP with the Server IP from the card (My servers → server). The command asks for the root password once:
    No ssh-copy-id – print the key with cat ~/.ssh/id_ed25519.pub and add it manually as in the section below.

Manual setup

Log in to the server with the password: ssh root@IP. Then:
PASTE_KEY_HERE – the whole public key line.

Check

Connect again:
Logged in without the server password – the key works. If you set a passphrase, you are asked for it: that is the password for the key on your computer, not for the server.

Disabling the password

Once key login works, you can turn the password off: there is nothing left to brute-force.
Check key login first. Turn the password off too early and you lose access to the server. If that happens, log in through Console on the server card, not every server has it.
  1. SSH settings – open them on the server:
  2. No password – find the PasswordAuthentication line, remove the leading # if there is one, and make it:
    Save: Ctrl+O, Enter, Ctrl+X. Also look in /etc/ssh/sshd_config.d/: a PasswordAuthentication yes line in files there overrides the main file, change it to no.
  3. Restart SSH – the current connection stays open:
    On AlmaLinux, Rocky, and CentOS the service is called sshd. Check the result with sshd -T | grep -i passwordauthentication: it should say passwordauthentication no. Before closing the connection, check key login in a second window.
Next: Server hardening, Firewall.