Remove SSH Keys Completely on Windows

1. Remove from SSH Agent

Open PowerShell or Git Bash:


                # 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 (should output "The agent has no identities.")
ssh-add -l
            

2. Delete Physical Key Files

You must manually delete the key files from your .ssh directory. By default, this is located at C:\Users\YourUsername\.ssh.


                # Using PowerShell:
Remove-Item ~/.ssh/id_github
Remove-Item ~/.ssh/id_github.pub
 
# Remove GitLab keys
Remove-Item ~/.ssh/id_gitlab
Remove-Item ~/.ssh/id_gitlab.pub
 
# Verify they are gone
Get-ChildItem ~/.ssh/
            

3. Clean SSH Config (Optional)

If you no longer plan on using SSH for these services, you should clear them from your configuration file.


                # Open the file in Notepad
notepad ~/.ssh/config
            

Remove or comment out the related Host entries:


                # Host github.com
#   HostName github.com
#   User git
#   IdentityFile ~/.ssh/id_github
 
# Host gitlab.com
#   HostName gitlab.com  
#   User git
#   IdentityFile ~/.ssh/id_gitlab
            

4. Remove from Windows Credential Manager (If Applicable)

Sometimes, if you typed a passphrase and Windows saved it, you may need to clear it from the Credential Manager.

  1. Open the Start menu and search for Credential Manager.
  2. Select Windows Credentials.
  3. Under the list of Generic Credentials, look for anything resembling git:https://github.com or SSH-related credentials.
  4. Expand the item and click Remove.

5. Remove from GitHub/GitLab

To fully revoke access, you must delete the public key from the web platforms:

  • GitHub: Settings > SSH and GPG keys > Delete the key
  • GitLab: Settings > SSH Keys > Remove the key

6. Verify Complete Removal


                # Check SSH agent identities
ssh-add -l
 
# Check remaining files
# PowerShell: 
Get-ChildItem ~/.ssh/
# Git Bash: 
ls -la ~/.ssh/
 
# Test connections (should fail)
ssh -T git@github.com
ssh -T git@gitlab.com
            

                # ⚠️ WARNING: This removes ALL SSH keys, known_hosts, and config files!
Remove-Item -Recurse -Force ~/.ssh/
 
# This will require recreating all SSH keys and configurations for all servers and services.