ssh-add -l like command in gpg

Hauke Laging mailinglisten at
Wed Sep 10 14:36:24 CEST 2014

Am Mi 10.09.2014, 13:20:01 schrieb Sudhir Khanger:
> Hello,
> Is there a way to tell if a GPG key's passphrase is cached or not?
> Just like ssh-add -l prints all the keys that are in current keychain
> ready to be used.

I am working on a Python script which does that as preparation for its 
main task. You could probably easily adapt it to your needs. Of course, 
it does not (cannot) solve the race condition Werner mentioned).

The general approach is to read the fingerprints of all available secret 
mainkeys and subkeys

gpg --with-colons --fingerprint --fingerprint --list-secret-keys

and check for each entry whether gpg-agent knows the fingerprint:

gpg-connect-agent "GET_PASSPHRASE --data --no-ask "\
"4F7E9F723D197D667842AE115F048E6F0E4B4494 t1 t2 t3" /bye

Crypto für alle:
OpenPGP: 7D82 FB9F D25A 2CE4 5241 6C37 BF4B 8EEF 1A57 1DF5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: </pipermail/attachments/20140910/f9e401d1/attachment.sig>

More information about the Gnupg-users mailing list