Given the following public key in Privacy Enhanced Mail (Base64 encoded DER) format:
$ wget https://apt.dockerproject.org/gpg -O dockerproject.gpg.pub.key
$ cat dockerproject.gpg.pub.key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFWln24BEADrBl5p99uKh8+rpvqJ48u4eTtjeXAWbslJotmC/CakbNSqOb9o
ddfzRvGVeJVERt/Q/mlvEqgnyTQy+e6oEYN2Y2kqXceUhXagThnqCoxcEJ3+KM4R
mYdoe/BJ/J/6rHOjq7Omk24z2qB3RU1uAv57iY5VGw5p45uZB4C4pNNsBJXoCvPn
TGAs/7IrekFZDDgVraPx/hdiwopQ8NltSfZCyu/jPpWFK28TR8yfVlzYFwibj5WK
dHM7ZTqlA1tHIG+agyPf3Rae0jPMsHR6q+arXVwMccyOi+ULU0z8mHUJ3iEMIrpT
X+80KaN/ZjibfsBOCjcfiJSB/acn4nxQQgNZigna32velafhQivsNREFeJpzENiG
HOoyC6qVeOgKrRiKxzymj0FIMLru/iFF5pSWcBQB7PYlt8J0G80lAcPr6VCiN+4c
NKv03SdvA69dCOj79PuO9IIvQsJXsSq96HB+TeEmmL+xSdpGtGdCJHHM1fDeCqkZ
hT+RtBGQL2SEdWjxbF43oQopocT8cHvyX6Zaltn0svoGs+wX3Z/H6/8P5anog43U
65c0A+64Jj00rNDr8j31izhtQMRo892kGeQAaaxg4Pz6HnS7hRC+cOMHUU4HA7iM
zHrouAdYeTZeZEQOA7SxtCME9ZnGwe2grxPXh/U/80WJGkzLFNcTKdv+rwARAQAB
tDdEb2NrZXIgUmVsZWFzZSBUb29sIChyZWxlYXNlZG9ja2VyKSA8ZG9ja2VyQGRv
Y2tlci5jb20+iQI4BBMBAgAiBQJVpZ9uAhsvBgsJCAcDAgYVCAIJCgsEFgIDAQIe
AQIXgAAKCRD3YiFXLFJgnbRfEAC9Uai7Rv20QIDlDogRzd+Vebg4ahyoUdj0CH+n
Ak40RIoq6G26u1e+sdgjpCa8jF6vrx+smpgd1HeJdmpahUX0XN3X9f9qU9oj9A4I
1WDalRWJh+tP5WNv2ySy6AwcP9QnjuBMRTnTK27pk1sEMg9oJHK5p+ts8hlSC4Sl
uyMKH5NMVy9c+A9yqq9NF6M6d6/ehKfBFFLG9BX+XLBATvf1ZemGVHQusCQebTGv
0C0V9yqtdPdRWVIEhHxyNHATaVYOafTj/EF0lDxLl6zDT6trRV5n9F1VCEh4Aal8
L5MxVPcIZVO7NHT2EkQgn8CvWjV3oKl2GopZF8V4XdJRl90U/WDv/6cmfI08GkzD
YBHhS8ULWRFwGKobsSTyIvnbk4NtKdnTGyTJCQ8+6i52s+C54PiNgfj2ieNn6oOR
7d+bNCcG1CdOYY+ZXVOcsjl73UYvtJrO0Rl/NpYERkZ5d/tzw4jZ6FCXgggA/Zxc
jk6Y1ZvIm8Mt8wLRFH9Nww+FVsCtaCXJLP8DlJLASMD9rl5QS9Ku3u7ZNrr5HWXP
HXITX660jglyshch6CWeiUATqjIAzkEQom/kEnOrvJAtkypRJ59vYQOedZ1sFVEL
MXg2UCkD/FwojfnVtjzYaTCeGwFQeqzHmM241iuOmBYPeyTY5veF49aBJA1gEJOQ
TvBR8Q==
=Fm3p
-----END PGP PUBLIC KEY BLOCK-----
The following commands will all show the long key id without adding it to your keyring:
$ gpg --list-packets dockerproject.gpg.pub.key | \
awk '/keyid:/{ print $2 }'
F76221572C52609D
$ gpg --with-colons dockerproject.gpg.pub.key 2>&1 | \
awk -F':' '/pub/{ print $5 }'
F76221572C52609D
$ gpg --dry-run --verbose --import dockerproject.gpg.pub.key 2>&1 | \
awk '/pub/{ print $3 }' | awk -F'/' '{ print $2 }'
F76221572C52609D
$ gpg --with-fingerprint --verbose dockerproject.gpg.pub.key 2>&1 | \
awk '/^sig/{ print $2 }'
F76221572C52609D
When using this version of gpg
:
$ gpg --version | head -n 1
gpg (GnuPG) 2.2.4
These commands are not very friendly or intuitive and spit out confusing messages like gpg: WARNING: no command supplied. Trying to guess what you mean ...
on STDERR. They also seem to often be subtly different between versions, for example my version sometimes requires --verbose
compared to some answers out there. This version does not have the --show-keys
flag which looks easier than most of the commands above.
Some useful information about key ids:
- Key ID Short Format:
2C52609D
- Key ID Long Format:
F76221572C52609D
- Key Signature:
58118E89F3A912897C070ADBF76221572C52609D
You should use long format as the short format is insecure
1
That imports to your keyring and/or agent, depending on gpg version; no keyserver is involved. PGP privatekey format includes the corresponding publickey and the displayed publickey info is obtained from the privatekey; no keyserver is involved. The answer how to display a privatekey is the same as your previous Q about displaying a publickey
– dave_thompson_085 – 2017-09-26T02:03:09.217