Technology

Log in with SSH keys

Demo Author

Published: 1 min read

A pine forest at night in green mist, with a soft light behind the trees

A key pair is safer than a password: the private key never leaves your computer, and nobody can guess it. Here is how to switch.

Create a key pair

On your own computer, run ssh-keygen -t ed25519 -C "maya@laptop" and accept the default location. Add a passphrase if other people use the computer.

Copy the public key to the server

ssh-copy-id [email protected] adds your public key to the server. Log in again: it should no longer ask for the server password.

Warning: Keep a way back

Keep your current session open until the new login works. If something goes wrong, you can still fix it from there.

Turn off password logins

Open /etc/ssh/sshd_config, set PasswordAuthentication no and PermitRootLogin no, then restart the service: sudo systemctl restart ssh.

A pine forest in violet mist, with a pink light glowing through the trees

Give a second admin access

Each person gets their own key. Add their public key on its own line in ~/.ssh/authorized_keys, and remove it when they leave.

Related posts

  • Set up your first server

    Guides

    From choosing a plan to your first login, with updates installed and a firewall in place. About ten minutes.

    A pine forest in teal mist, a bright path running between the trees