SSH Key Generation Guide
Generate SSH Keys
# Ed25519 โ recommended (modern, smaller, faster)
ssh-keygen -t ed25519 -C "your_email@example.com"
# RSA 4096 โ for compatibility with older systems
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# 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
| Type | Security | Speed | Compatibility |
|---|---|---|---|
| Ed25519 | Excellent | Fast | OpenSSH 6.5+ |
| RSA 4096 | Strong | Moderate | Universal |
| ECDSA | Good | Fast | Wide |
| RSA 2048 | Acceptable | Moderate | Universal |