Set Up Signed Commits on GitHub
How-to
GitHub
Authentication
Verification
A quick guide to setting up commit verification using a GPG key.

Acknowledgement
This article merely collates information from the following sources:
- Adding a GPG key to your GitHub account
- Generating a new GPG key
- How to understand the
gpg failed to sign the data
problem in git
For more information and troubleshooting, please visit these sources as they contain additional guidance which may be helpful for operating systems other than macos.
The Scenario
You need to set up commit verification on your computer for the first time. Possibly you have changed computer and need to quickly set up once more. You are on macos with access to the terminal.
What you’ll need:
Instructions
- In terminal, run:
terminal
--global commit.gpgsign true
git config --global tag.gpgsign true git config
- Visit GPG suite and download the installer.
- Follow the installation steps and quit the screen that attempts to create a new key
- In terminal, create a key with:
terminal
--full-generate-key gpg
- At the prompt, accept the default values for key type, size and persistence
- Ensure you enter your real name, as it appears on GitHub, under your GitHub profile avatar. Use the primary Email associated with your GitHub account.
- Enter a passphrase, confirm it and store it in a secure password wallet. You will need it again in the final step of this process
- Print out the long format of the key details with:
terminal
--list-secret-keys --keyid-format=long gpg
- Copy the long form of the key ID from the example output labelled as
<COPY THIS BIT ONLY>
, do not include the preceeding forward slash:
--list-secret-keys --keyid-format=long
$ gpg /Users/hubot/.gnupg/secring.gpg
------------------------------------
/<COPY THIS BIT ONLY> 2023-10-23
sec XXXX
uid your username/XXXXXXXXXXXXXXXX 2023-10-23 ssb xxxXXXX
- Adjust this command with your copied key ID and run in terminal:
terminal
--global user.signingkey <INSERT YOUR KEY ID> git config
- Paste your key ID into the command below and execute in terminal:
terminal
--armor --export <INSERT YOUR KEY ID> gpg
- Copy the output, including the
-----BEGIN PGP PUBLIC KEY BLOCK-----
and-----END PGP PUBLIC KEY BLOCK-----
sections. - Go to the GPG Keychain app, it should have detected the key in your clipboard and ask you to import the key to your keychain. Click OK
- Over to your web brower, go to GitHub profile pic settings SSH and GPG keys
- Add a new key to your account, give it an appropriate title and paste the key from your clipboard
- GitHub will ask you to authenticate in order to make this change
- Now ensure Git knows where to look for your GPG program:
terminal
where gpg
Copy the path to the GPG program.
- Update the command below with the path in your clipboard:
terminal
--global gpg.program "<INSERT/PATH/HERE>" git config
- Check that your git config file looks as expected:
terminal
--global --list git config
Example output:
user.name=<YOUR GITHUB USERNAME>
user.email=<YOUR PRIMARY GITHUB EMAIL>
user.signingkey=<YOUR GPG KEY ID>
commit.gpgsign=true
gpg.program=<PATH TO YOUR GPG PROGRAM>
tag.gpgsign=true
- The next time you need to commit, you will be asked to enter the passphrase you saved to your password wallet in order to add the key to your keychain
Troubleshooting
gpg: signing failed: Inappropriate ioctl for device
Add the below to your initialisation file (eg ~/.zshrc or equivalent):
~/.zshrc
=$(tty)
GPG_TTY export GPG_TTY
Restart your terminal. Try to commit once more. You’ll be asked for the GPG passphrase that you stored in your password wallet.
fin!