Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisswanda/76c7af3bc0d8c42618216aa5ad8b1371 to your computer and use it in GitHub Desktop.
Save chrisswanda/76c7af3bc0d8c42618216aa5ad8b1371 to your computer and use it in GitHub Desktop.
Remove SSH key from GPG agent keyring
keys=$(gpg-connect-agent 'keyinfo --list' /bye | awk '{print $3}')
for key in $keys; do gpg-connect-agent "delete_key $key --force" /bye; done
@jean-christophe-manciot
Copy link

jean-christophe-manciot commented Oct 4, 2021

Actually, with your first line, all keys are deleted from the gpg-agent keyring, i.e SSH keys and GPG secret keys.
You can verify your GPG secret keys with:

gpg --list-secret-keys --with-keygrip

To remove only SSH keys:

ssh_keys=$(gpg-connect-agent 'keyinfo --ssh-list' /bye | awk '{print $3}')
for key in $ssh_keys; do gpg-connect-agent "delete_key --force $key" /bye; done
# Verifying that all SSH keys are not cached anymore by gpg-agent
ssh-add -l

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment