Remove Old SSH Keys
February 10, 2025 ยท AI Conversations
### 1. **Remove from `~/.ssh/known_hosts`**
If you want to remove a specific host's SSH key (e.g., due to a changed server fingerprint):
ssh-keygen -R <hostname_or_IP>
For example, to remove a key for `example.com`:
ssh-keygen -R example.com
### 2. **Manually Edit `known_hosts` (If Needed)**
If the above command does not work, you can manually edit the file:
nano ~/.ssh/known_hosts
– Find the line that contains the old key for the host/IP and delete it.
– Save the file (`CTRL + X`, then `Y`, then `ENTER`).
### 3. **Remove SSH Private and Public Keys**
If you want to remove old SSH keys from your system completely:
rm -f ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
If you're using different key types (`id_ed25519`, `id_ecdsa`, etc.), remove them accordingly:
rm -f ~/.ssh/id_* ~/.ssh/authorized_keys
### 4. **Restart SSH Agent (If Using One)**
If you are using an SSH agent, clear the loaded keys:
ssh-add -D
Let me know if you need more help! ๐