My gnupg keyring contains hundreds of unnecessary entries. How would I remove the expired, revoked and unsigned keys from it?
I would like to keep the keys that have signed my key, and import new keys only as required. I'd previously imported the entire web of trust for my key's signatories. It would seem that one of my key signers has picked up a very large number of signatures in his travels, and these are now clogging up my keyring.
I've used User Name as being the name associated with the key.
Sorry that isn't very imaginative.
I think gpg is pretty wide in its user assignments,
e.g., the name for my private key is “Charles Lockhart”,
but I can reference that by just putting in “Lockhart”.
That doesn't make any sense, sorry.
to delete a public key (from your public key ring):
$ gpg --delete-key "User Name"
This removes the public key from your public key ring.
NOTE: If there is a private key on your private key ring associated with this public key, you will get an error! You must delete your private key for this key pair from your private key ring first.
to delete a private key (a key on your private key ring):
$ gpg --delete-secret-key "User Name"
This deletes the secret key from your secret key ring.
tell gpg to output keys in a parsable format (the docs for this format are a little hidden: the man page says they are in doc/DETAILS in the source, my distro installed them in /usr/share/doc/gunpg/DETAILS)
tell awk to use colon as field delimiter: -F:
only select lines where the first field is "pub", these are public keys
only select lines where the second field is either "e" or "r", these are revoced or expired keys
print only field five of the selected lines, that is the key id
use xargs to hand the lines to gpg and delete them
rm -r ~/.gnupg. This will remove your private keys too, but you did say all …