Hostxpeed
Login Get Started →
Security

How to Rotate SSH Keys

4 min read
25 views
Jun 10, 2026

Step 1: Generate New Key Pair on Client

ssh-keygen -t ed25519 -f ~/.ssh/new_key -C "rotation-$(date +%Y%m)"

Step 2: Copy New Public Key to Server

ssh-copy-id -i ~/.ssh/new_key.pub username@server

Step 3: Test Login with New Key

ssh -i ~/.ssh/new_key username@server

Step 4: Remove Old Public Key from authorized_keys

ssh username@server "sed -i '/old-key-comment/d' ~/.ssh/authorized_keys"

Step 5: Update SSH Config

nano ~/.ssh/config
IdentityFile ~/.ssh/new_key

Was this article helpful?