← All posts

SSH keys done properly

19 January 2022 · 1 min read
#linux#security

Passwords over SSH are an open invitation for bots. Keys are better, but only if you treat them well.

What I do now:

  • Use ed25519 keys. ssh-keygen -t ed25519 -C "laptop-2022". Short, fast and strong.
  • Put a passphrase on the key and let ssh-agent remember it, so you only type it once per session.
  • One key per device. If a laptop is lost, you remove one public key, not all of them.
  • Turn off password logins on the server: PasswordAuthentication no in sshd_config, then restart sshd. Test from a second session before you close the first one.
  • Use ~/.ssh/config. Give each server a short name with its user, port and key. No more long commands.
  • Check permissions. ~/.ssh should be 700 and private keys 600, or SSH will refuse to use them.

It takes ten minutes to set up and removes a whole class of problems.

T
Written by Teza Wynn Htut

Cloud and infrastructure engineer in Auckland. I write down the fixes and lessons from things I build, and make tutorial videos on YouTube.

Watch on YouTube