I need to get the public key ID from GPG. Everything on SO discusses importing, exporting, etc. In the example below, I need to get the ABCD1234
value to use in a bash script?
$ gpg --list-keys
/Users/jblow/.gnupg/pubring.gpg
---------------------------------
pub 2048R/ABCD1234 2016-09-20
uid [ultimate] Joe Blow <[email protected]>
sub 2048R/JDKKHU76 2016-09-20
I was facing the same requirement today (extracting the key ID in order to use it together with duplicity in a bash script).
In the man page of gpg I read:
For scripted or other unattended use of gpg make sure to use the machine-parseable interface and not the default interface which is intended for direct use by humans. The machine-parseable inter- face provides a stable and well documented API independent of the locale or future changes of gpg. To enable this interface use the options --with-colons and --status-fd. For certain operations the option --command-fd may come handy too. See this man page and the file `DETAILS' for the specifi- cation of the interface.
I managed to extract the key ID I wanted by doing:
gpg --list-signatures --with-colons | grep 'sig' | grep 'the Name-Real of my key' | head -n 1 | cut -d':' -f5
PS: https://devhints.io/gnupg helped ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With