Remove SSH Keys Completely on Linux

1. Remove from SSH agent


                # Remove specific keys
ssh-add -d ~/.ssh/id_github
ssh-add -d ~/.ssh/id_gitlab
 
# OR remove ALL keys from the agent
ssh-add -D
 
# Verify removal
ssh-add -l
            

2. Delete key files


                rm ~/.ssh/id_github ~/.ssh/id_github.pub
rm ~/.ssh/id_gitlab ~/.ssh/id_gitlab.pub
 
ls -la ~/.ssh/
            

3. Clean SSH config (optional)


                nano ~/.ssh/config
            

Remove or comment out the related Host github.com / Host gitlab.com blocks.

4. Desktop keyring (optional)

If your desktop environment stored the passphrase in GNOME Keyring, KWallet, or similar, you may remove obsolete SSH entries from your wallet/keyring app if they still appear. This is optional if you already deleted the key files and removed keys from the agent.

5. Remove from GitHub/GitLab

  • GitHub: Settings → SSH and GPG keys → delete the key
  • GitLab: Settings → SSH Keys → remove the key

6. Verify complete removal


                ssh-add -l
ls -la ~/.ssh/
 
# Should fail or prompt if keys are gone
ssh -T git@github.com
ssh -T git@gitlab.com
            

Nuclear option: remove everything under ~/.ssh


                # ⚠️ WARNING: This removes ALL SSH keys, known_hosts, and config for this user
rm -rf ~/.ssh/
 
# You will need to recreate keys and trust prompts for all hosts