Find us on social media
SSHKeysAuthentication4 min read
Configure SSH key authentication
Generate ed25519 keys, copy to server, disable password auth and manage multiple keys.
Why use SSH keys?
SSH keys are more secure than passwords:
- Virtually impossible to brute-force
- Not transmitted over the network
- Allow passwordless access
- Can be revoked individually
Step 1: Generate ed25519 keys
bash
ssh-keygen -t ed25519 -C "your-email@example.com"Press Enter for the default path. Enter a secure passphrase.
Generated files:
~/.ssh/id_ed25519→ private key (never share)~/.ssh/id_ed25519.pub→ public key (goes to server)
Step 2: Copy to server
bash
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your-serverManual method:
bash
# On the server
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo 'YOUR_PUBLIC_KEY' >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keysStep 3: Disable password authentication
Edit /etc/ssh/sshd_config:
terminal
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication nobash
sudo systemctl restart sshdSSH Agent
bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519Multiple keys for different servers
Create ~/.ssh/config:
terminal
Host production
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519_prod
Port 2222
Host staging
HostName 203.0.113.20
User deploy
IdentityFile ~/.ssh/id_ed25519_stagingConnect with: ssh production
Key rotation
Every 6-12 months:
- Generate a new key pair
- Add the new public key to the server
- Verify it works
- Remove the old key from
authorized_keys - Delete old key files locally
Recommendations
- Always use ed25519 (more secure and faster than RSA)
- Protect private keys with a passphrase
- Never push private keys to repositories
- Use different keys for different services
- Periodically review authorized_keys
Was this guide helpful?