SSH Key Generation Guide

Generate SSH Keys

# Ed25519 — recommended (modern, smaller, faster) ssh-keygen -t ed25519 -C "[email protected]" # RSA 4096 — for compatibility with older systems ssh-keygen -t rsa -b 4096 -C "[email protected]" # Specify output file ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_work -C "work key"

Add Key to ssh-agent

# Start ssh-agent eval "$(ssh-agent -s)" # Add key ssh-add ~/.ssh/id_ed25519 # macOS — add to keychain ssh-add --apple-use-keychain ~/.ssh/id_ed25519 # List loaded keys ssh-add -l

Copy Public Key to Server

# Recommended method ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server # Manual method cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

~/.ssh/config

Host work HostName work.example.com User deploy IdentityFile ~/.ssh/id_ed25519_work AddKeysToAgent yes Host github.com User git IdentityFile ~/.ssh/id_ed25519 IdentitiesOnly yes

Key Types Comparison

TypeSecuritySpeedCompatibility
Ed25519ExcellentFastOpenSSH 6.5+
RSA 4096StrongModerateUniversal
ECDSAGoodFastWide
RSA 2048AcceptableModerateUniversal