I am borrowing this from pstadler because it is really good
https://github.com/pstadler/keybase-gpg-github/blob/master/README.md
Set up Keybase.io, GPG & Git to sign commits on GitHub
This is a step-by-step guide on how to create a GPG key on keybase.io, adding it to a local GPG setup and use it with Git and GitHub.
Although this guide was written for macOS, most commands should work in other operating systems as well.
There’s a video published by Timothy Miller explaining some parts of this guide. Discussion on Hacker News.
Note: If you don’t want to use Keybase.io, follow this guide instead. For manually transferring keys to different hosts, check out this answer on Stack Overflow.
Requirements
|
|
You should already have an account with Keybase and be signed in locally using $ keybase login
. In case you need to set up a new device first, follow the instructions provided by the keybase command during login.
Make sure your local version of Git is at least 2.0 ($ git --version
) to automatically sign all your commits. If that’s not the case, use Homebrew to install the latest Git version: $ brew install git
.
Create a new GPG key on keybase.io
|
|
Set up Git to sign all commits
|
|
Add public GPG key to GitHub
|
|
Import key to GPG on another host
|
|
Troubleshooting: gpg failed to sign the data
If you cannot sign a commit after running through the above steps, and have an error like:
|
|
You can run echo "test" | gpg --clearsign
to find the underlying issue.
If the above succeeds without error, then there is likely a configuration problem that is preventing git from selecting or using the secret key. Confirm that your gitconfig user.email
matches the secret key that you are using for signing.
Optional: Set as default GPG key
|
|
Optional: Fix for Git UIs
If you use a UI such as Git Tower or Github Desktop, you may need to configure git to point to the specific gpg executable:
|
|
Optional: Disable TTY
If you have problems with making autosigned commits from IDE or other software add no-tty config
|
|
Optional: Setting up TTY
Depending on your personal setup, you might need to define the tty for gpg
whenever your passphrase is prompted. Otherwise, you might encounter an Inappropriate ioctl for device
error.
|
|
Optional: In case you’re prompted to enter the password every time
Some people found that this works out of the box w/o following these steps.
Method 1 - gpg-agent + pinentry-mac
Install pinentry-mac:
|
|
Set up the agent:
|
|
Now git commit -S
, it will ask your password and you can save it to macOS
keychain.
Method 2 - GPG Suite
Some people find that pinentry installed with brew does not allow the password to be saved to macOS’s keychain.
If you do not see “Save in Keychain” after following Method 1, first uninstall the version of pinentry-mac installed with brew:
|
|
Now install the GPG Suite versions, available from gpgtools.org, or from brew by running:
|
|
Once installed, open Spotlight and search for “GPGPreferences”, or open system preferences and select “GPGPreferences”
Select the Default Key if it is not already selected, and ensure “Store in OS X Keychain” is checked:
The gpg-agent.conf
is different from Method 1:
Set up the agent:
|
|