Table of Contents

SSH Security

SSH security depends on key management, file permissions, and thoughtful server configuration. Follow best practices to prevent unauthorized access.

Key generation and storage:

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:

StrictHostKeyChecking accept-new     # accept new, warn if changed
StrictHostKeyChecking ask            # prompt for every unknown key
StrictHostKeyChecking yes            # require known key

Key rotation:

Monitor for unauthorized keys:

$ cat ~/.ssh/authorized_keys

Review regularly for entries you didn't add.

SSH version and updates:

On servers, apply ssh-security hardening practices.