Remove SSH Keys Completely on Mac

  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 agent
ssh-add -D
 
# Verify removal
ssh-add -l
            
  1. Remove from macOS Keychain

                # Remove specific keys from keychain
security delete-generic-password -s "SSH: ~/.ssh/id_github"
security delete-generic-password -s "SSH: ~/.ssh/id_gitlab"
 
# OR use Keychain Access app:
# 1. Open "Keychain Access" 
# 2. Search for your key names (id_github, id_gitlab)
# 3. Right-click and delete entries
            
  1. Delete Physical Key Files

                # Remove GitHub keys
rm ~/.ssh/id_github
rm ~/.ssh/id_github.pub
 
# Remove GitLab keys  
rm ~/.ssh/id_gitlab
rm ~/.ssh/id_gitlab.pub
 
# List remaining keys to verify
ls -la ~/.ssh/
            
  1. Clean SSH Config (Optional)

                # Edit SSH config
nano ~/.ssh/config
 
# Remove or comment out the Host entries:
# Host github.com
#   HostName github.com
#   User git
#   IdentityFile ~/.ssh/id_github
#   AddKeysToAgent yes
#   UseKeychain yes
 
# Host gitlab.com
#   HostName gitlab.com  
#   User git
#   IdentityFile ~/.ssh/id_gitlab
#   AddKeysToAgent yes
#   UseKeychain yes
            
  1. Remove from GitHub/GitLab
  • GitHub: Settings > SSH and GPG keys > Delete the key
  • GitLab: Settings > SSH Keys > Remove the key
  1. Verify Complete Removal

                # Check SSH agent
ssh-add -l
 
# Check remaining files
ls -la ~/.ssh/
 
# Test connections (should fail)
ssh -T git@github.com
ssh -T git@gitlab.com
            

                # ⚠️ WARNING: This removes ALL SSH keys and config
rm -rf ~/.ssh/
 
# This will require recreating all SSH keys and configurations