Query the default key via command line?

Immanuel Scholz immanuel.scholz at tu-dresden.de
Fri Aug 31 11:32:34 CEST 2007


Hi,

>> I am writing an application that accesses the "gpg" executable. How do I
>> retrieve the current default key id via the command line?
> 
> No explicit way.  You may run a test encrytiopn, though.

This triggers any password agent, doesn't it?

Hm, maybe using something like "--password-fd 0" but isn't this nasty?
So unless some more direct approach, I can use something like this:

echo "" | gpg --passphrase-fd 0 --batch -s --status-fd 1 \
   2> /dev/null | grep USERID_HINT | cut -d " " -f 3

Really ugly, though... (and of course, the greps and cuts have to be
done within the program to be usable under windows ;)


>> This is nasty and does not work under non-linux ;). So is there an
>> option I didn't recognized to display the default key id (preferable the
>> full-id)?
> 
> Use gpgconf from the gnupg package:
> 
>   $ gpgconf --list-options gpg
>   Monitor:1:0:Options controlling the diagnostic output:0:0::::
>   verbose:4:0:verbose:0:0::::
>   quiet:0:0:be somewhat more quiet:0:0::::
>   Configuration:1:2:Options controlling the configuration:0:0::::
>   default-key:0:0:use NAME as default secret key:1:1:NAME:::"5B0358A2
>   encrypt-to:0:0:encrypt to user ID NAME as well:1:1:NAME:::"5B0358A2
>   Keyserver:1:0:Configuration for Keyservers:0:0::::
>   keyserver:0:0:use keyserver at URL:1:1:URL:::"hkp%3a//minsky.surfnet.nl

Doesn't work for me:

~$ cat .gnupg/gpg.conf | grep ^default
default-key 91723535
~$ gpgconf --list-options gpg
Monitor:1:0:Options controlling the diagnostic output:0:0::::
verbose:4:0:verbose:0:0::::
quiet:0:0:be somewhat more quiet:0:0::::
Keyserver:1:0:Configuration for Keyservers:0:0::::
keyserver:0:0:use keyserver at URL:1:1:URL:::"hkp%3a//subkeys.pgp.net
~$

Ciao, Imi.

-- 
DF0E A04F 7063 69C5 A76B  7557 0A77 608F 9172 3535



More information about the Gnupg-devel mailing list