Search code examples
shgnupgpgp

How to extract image from PGP key on command line?


I've created a private PGP key and then added a photo to it in my Ubuntu's Passwords and keys manager. I can see the photo there, but is there any way to view it from shell and export it as image file?


Solution

  • To view the image, use this:

    gpg --list-options show-photos --list-keys \
      [key identifier (e-mail or ID), leave out to show all keys and photos]
    

    It internally uses xloadimage, which wasn't preinstalled on my Ubuntu 18.04, so you can either install it, or use --photo-viewer "eog %i" (expands %i to temporary file name).


    To export the image, I haven't found any simpler way than cat the data (if %i isn't specified, gpg sends image data on stdin) to a file like this:
    (%k - keyID; %t - extension --> filenames like 0x02468ACE.jpg)

    gpg --list-options show-photos --photo-viewer "cat > <path>/0x%k.%t" --list-keys [key_identifier]
    

    One more tip - to show image of every key you use to verify something, put this into your .gnupg/gpg.conf:

    verify-options show-photos
    # if you don't have xloadimage:
    photo-viewer eog %i