mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
128 words
1 minute
SSH Key Management: A Complete Guide
2026-06-28

Generating SSH Keys#

# Ed25519 (recommended — fast, secure, short keys)
ssh-keygen -t ed25519 -C "your@email.com"
# RSA 4096 (broader compatibility)
ssh-keygen -t rsa -b 4096 -C "your@email.com"

You’ll be prompted for a file location and passphrase. Always use a passphrase for production keys.

Managing Multiple Keys#

Edit ~/.ssh/config to assign different keys to different hosts:

# Personal GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work GitLab
Host gitlab.work.com
HostName gitlab.work.com
User git
IdentityFile ~/.ssh/id_ed25519_work
# Production server
Host prod
HostName 203.0.113.50
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
Port 2222

Now you can simply ssh prod instead of typing the full command.

Adding Keys to the SSH Agent#

# Start the agent
eval "$(ssh-agent -s)"
# Add your key
ssh-add ~/.ssh/id_ed25519
# On macOS, add to Keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Copying Public Keys to Servers#

# The easy way
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
# Manual way (if ssh-copy-id is unavailable)
cat ~/.ssh/id_ed25519.pub | ssh user@server \
"mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Security Best Practices#

  1. Use Ed25519 keys — they’re more secure and performant than RSA
  2. Always set a passphrase — protects you if your key file is stolen
  3. Set proper permissions:
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/id_ed25519
    chmod 644 ~/.ssh/id_ed25519.pub
    chmod 600 ~/.ssh/config
  4. Disable password authentication on servers:
    /etc/ssh/sshd_config
    PasswordAuthentication no
    PubkeyAuthentication yes
  5. Rotate keys periodically — treat them like passwords
  6. Use ssh-agent forwarding sparingly — it can be a security risk

Troubleshooting#

# Test connection with verbose output
ssh -vT git@github.com
# Check which key is being used
ssh -v user@server 2>&1 | grep "Offering"
# Fix permission issues
chmod 600 ~/.ssh/id_ed25519

SSH keys are the foundation of secure remote access. Take the time to set them up properly, and you’ll save yourself countless headaches.

Share

If this article helped you, please share it with others!

SSH Key Management: A Complete Guide
https://blog.levifree.com/posts/ssh-key-management/
Author
LeviFREE
Published at
2026-06-28
License
CC BY-NC-SA 4.0

Some information may be outdated

Table of Contents