GPG Signing key
About 628 wordsAbout 2 min
GPGGit
2026-06-04
๐ Why Use GPG Signature
Note
GPG signature verifies the identity and integrity of your commits. When verified, GitHub displays a Verified badge on your commits, boosting their credibility and security.
๐ฆ Install GnuPG
Install using Homebrew. See Homebrew Setup Guide.
$ brew install gnupg๐ Generate GPG Key
Start the key generation
$ gpg --full-generate-keyChoose key type
Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? 1Set key size
RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (3072) 4096Set expiration
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 Key is valid for? (0) 1yEnter your info
Real name: Your Name Email address: [email protected] Comment: (optional - can be left blank)The email must match your GitHub account email, or verification won't work!
Set a passphrase
Enter passphrase: (enter a secure password) Repeat: (confirm)
๐ View Your Keys
$ gpg --list-secret-keys --keyid-format=longExample output:
sec rsa4096/3AA5C34371567BD2 2026-06-04 [SC] [expires: 2027-06-04]
85E38EC66371567BD2E7D6C4216A591059929882
uid [ultimate] Your Name <[email protected]>
ssb rsa4096/42B317FD4BA89E7A 2026-06-04 [E] [expires: 2027-06-04]Extract the 16-character key ID after the / on the sec line, like 3AA5C34371567BD2
โ๏ธ Configure Git to Use GPG
1๏ธโฃ Enable GPG signing globally
$ git config --global commit.gpgsign true
$ git config --global tag.gpgsign true2๏ธโฃ Set your signing key
$ git config --global user.signingkey 3AA5C34371567BD23๏ธโฃ Configure name and email
$ git config --global user.name "yourname"
$ git config --global user.email "[email protected]"4๏ธโฃ pinentry-mac Optional
Want a prompt when entering your PIN or passphrase? Install pinentryโmac.
$ brew install pinentry-mac
$ echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
$ killall gpg-agent๐ Export & Upload Public Key to GitHub
๐ Export your public key
$ gpg --armor --export 3AA5C34371567BD2Output:
-----BEGIN PGP PUBLIC KEY BLOCK-----
mI0EZmfQxQEEALzX2hZ3...๏ผlots of characters in the middle๏ผ...kMQQA
AKCAKQDfw=
-----END PGP PUBLIC KEY BLOCK-----๐ค Add it to GitHub
Open GitHub Settings
Create a new GPG key
Click the "New GPG key" buttonPaste your public key
Copy the entire key (everything from-----BEGINto-----END) into the text boxSave
Click "Add GPG key"
โ Test Your GPG Signature
Make a commit
$ git commit -S -m "Test GPG signature"Info
- The
-Sflag forces signing for this commit - If you set
commit.gpgsign true, you can skip-S - It'll prompt for your GPG passphrase (the one you set earlier)
- The
Push it
$ git pushCheck on GitHub
Visit your repo and look at your commit historyโyou should see the green
Verifiedbadge
๐ References
Changelog
f8645-docs(gpg): ๐ add GPG doccumentationon
Copyright
Copyright Ownership:Emirio Bomb
License under:Attribution 4.0 International (CC-BY-4.0)
