SSH security depends on key management, file permissions, and thoughtful server configuration. Follow best practices to prevent unauthorized access.
Key generation and storage:
ssh-keygen -t ed25519 -C "user@host"File permissions (critical):
$ chmod 700 ~/.ssh # directory $ chmod 600 ~/.ssh/id_* # private keys $ chmod 644 ~/.ssh/*.pub # public keys $ chmod 644 ~/.ssh/authorized_keys # on server $ chmod 644 ~/.ssh/config # config file
Incorrect permissions cause Permission denied (publickey) errors.
Host key verification:
ssh-keyscan host | ssh-keygen -lf -~/.ssh/config:StrictHostKeyChecking accept-new # accept new, warn if changed StrictHostKeyChecking ask # prompt for every unknown key StrictHostKeyChecking yes # require known key
Key rotation:
authorized_keys files on serversMonitor for unauthorized keys:
$ cat ~/.ssh/authorized_keys
Review regularly for entries you didn't add.
SSH version and updates:
ssh -V shows version
On servers, apply ssh-security hardening practices.