GPG

Installation

macOS

You can install GPG on macOS using:

$ brew install gpg

Workflow

Getting existing key

To get an existing key id use:

gpg --list-secret-keys --keyid-format LONG

The key id will be available at

gpg --list-secret-keys --keyid-format LONG   /home/foo/.gnupg/pubring.gpg
------------------------------
sec rsa2048/7FFFC09ACAC05FD0 2017-06-02 [SC] [expires: 2019-06-02]   5538B0F643277336BA7F0E457FFFC09ACAC05FD0   uid [ultimate] foo <foo@[example.com](http://realaddress.com)>   ssb rsa2048/95E8A289DFE77A84 2017-06-02 [E] [expires: 2019-06-02]

The key id we want, in this case is 7FFFC09ACAC05FD0.

To retrieve the public key use

gpg --armor --export 7FFFC09ACAC05FD0

And the result will be

-----BEGIN PGP PUBLIC KEY BLOCK-----

... The actual key ...
-----END PGP PUBLIC KEY BLOCK-----

Troubleshooting

macOS

Can’t access keychain from UI

If a program cannot access the keychain from the UI, probably there’s some problem in prompting you for the passphrase. You can install, for instance pinentry to solve this. Install it with

$ brew install pinentry-mac

and then register pinentry as the passphrase input option:

$ echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf