DEV Community

zemse
zemse

Posted on • Edited on

42

Setup GPG on macOS

Install

brew install gpg
Enter fullscreen mode Exit fullscreen mode

Create new key

# generate key
gpg --full-generate-key

# get the public key using key ID
gpg --armor --export XXXXXX

# set the key ID in git
git config --global user.signingkey XXXXXXX

# always sign commits
git config commit.gpgsign true
Enter fullscreen mode Exit fullscreen mode

Setup keychain

gpg collects password from cli. This causes issues if using vscode to create a commit. So input can be taken from a popup or keychain.

brew install pinentry-mac
Enter fullscreen mode Exit fullscreen mode

The brew installation will print these caveats:

==> Caveats
You can now set this as your pinentry program like

~/.gnupg/gpg-agent.conf
    pinentry-program /opt/homebrew/bin/pinentry-mac
Enter fullscreen mode Exit fullscreen mode

So just create a ~/.gnupg/gpg-agent.conf file if it doesn't exist and put the line pinentry-program /opt/homebrew/bin/pinentry-mac in it.

Now, to check if it works.

1.gpg --list-keys to print the existing keys.

  1. pkill -TERM gpg-agent.
  2. Restart the terminal.
  3. echo test | gpg -e -r <PUT THE KEY ID HERE> | gpg -d

This should open a pin entry popup and make sure "save in keychain" option is selected.

More links

Documentation on GitHub for setup: https://docs.github.com/en/authentication/managing-commit-signature-verification

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
jonathanyeong profile image
Jonathan Yeong

Great post! Helped me with my GPG setup

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay