Get yourself verified on GitHub using GPG keys (on Mac)
Update November 2026: I’ve updated this post. The package names were not correct (gnupg is the package, you don’t need gpg-agent separately) and the path to pinentry-mac is different on Macs with an Apple Silicon chip.
requirements
Installation
1
2
3
| brew install gnupg
brew install pinentry-mac
brew install git
|
How to create a PGP key on macOS
- Open the Terminal app and type the following command to generate a PGP key:
1
| gpg --full-generate-key
|
- Select the kind of key you want:
1
2
3
4
5
6
7
8
9
| Please select what kind of key you want:
(1) RSA and RSA
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(9) ECC (sign and encrypt) *default*
(10) ECC (sign only)
(14) Existing key from card
Your selection?
|
- Select the key size:
1
2
3
4
5
| Please select which elliptic curve you want:
(1) Curve 25519 *default*
(4) NIST P-384
(6) Brainpool P-256
Your selection?
|
- Enter the key expiration:
1
2
3
4
5
6
| Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
|
- Confirm the key expiration:
- Enter your user ID information:
1
2
3
| Real name:
Email address:
Comment:
|
After creating the GPG keys, you need to add it to your GitHub account
First look up the ID of your key. You need it later as well:
1
| gpg --list-secret-keys --keyid-format=long
|
The ID is the part after the / on the line that starts with sec.
- Copy the PGP key to your clipboard:
1
| gpg --armor --export <your_email>
|
- Open GitHub, go to your account settings and click on SSH and GPG keys.
- Click on New GPG key, enter any title, paste the PGP key you copied in the previous step, and click on Add GPG key.
- Open the Terminal app and type the following command to configure Git to sign commits and tags:
1
2
3
| git config --global user.signingkey <your_key_id>
git config --global commit.gpgsign true
git config --global tag.gpgsign true
|
- Open the Terminal app and type the following command to configure Git to use GPG for signing:
1
| git config --global gpg.program gpg
|
Now we need to configure GPG to use pinentry-mac
- Open the Terminal app and type the following command to configure GPG to use pinentry-mac:
First find out where pinentry-mac is installed:
On a Mac with an Apple Silicon chip that is /opt/homebrew/bin/pinentry-mac. On an Intel Mac it is /usr/local/bin/pinentry-mac. Use the path you get:
1
| echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
|
- Open the Terminal app and type the following command to restart GPG agent:
1
| gpgconf --kill gpg-agent
|
- Open the Terminal app and type the following command to verify that pinentry-mac is being used:
1
| echo "test" | gpg --clearsign
|
- You should see a popup window asking for your passphrase: