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-agentremember 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 noinsshd_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.
~/.sshshould be700and private keys600, or SSH will refuse to use them.
It takes ten minutes to set up and removes a whole class of problems.