Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pstadler/keybase-gpg-github
Step-by-step guide on how to create a GPG key on keybase.io, adding it to a local GPG setup and using it with Git and GitHub.
https://github.com/pstadler/keybase-gpg-github
cryptography gpg guide howto keybase signing
Last synced: 25 days ago
JSON representation
Step-by-step guide on how to create a GPG key on keybase.io, adding it to a local GPG setup and using it with Git and GitHub.
- Host: GitHub
- URL: https://github.com/pstadler/keybase-gpg-github
- Owner: pstadler
- Created: 2016-04-06T09:51:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-10T17:26:18.000Z (over 1 year ago)
- Last Synced: 2024-10-01T17:05:30.890Z (about 1 month ago)
- Topics: cryptography, gpg, guide, howto, keybase, signing
- Homepage:
- Size: 277 KB
- Stars: 2,633
- Watchers: 37
- Forks: 182
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - keybase-gpg-github - 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. | pstadler | 2453 | (Others)
README
# 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](https://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](https://www.youtube.com/watch?v=4V-7KnhcrbY) published by [Timothy Miller](https://github.com/tjacobdesign) explaining some parts of this guide. [Discussion](https://news.ycombinator.com/item?id=12289481) on Hacker News.
> **Note**: If you **don't** want to use Keybase.io, follow [this guide][1] instead.
> For manually transferring keys to different hosts, check out this [answer on Stack Overflow][2].[1]: https://help.github.com/articles/generating-a-new-gpg-key/
[2]: https://stackoverflow.com/a/3176373/571227## Requirements
```sh
$ brew install gpg
$ brew install --cask keybase
```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
```sh
$ keybase pgp gen --multi
# Enter your real name, which will be publicly visible in your new key: Patrick Stadler
# Enter a public email address for your key: [email protected]
# Enter another email address (or when done):
# Push an encrypted copy of your new secret key to the Keybase.io server? [Y/n] Y
# ▶ INFO PGP User ID: Patrick Stadler [primary]
# ▶ INFO Generating primary key (4096 bits)
# ▶ INFO Generating encryption subkey (4096 bits)
# ▶ INFO Generated new PGP key:
# ▶ INFO user: Patrick Stadler
# ▶ INFO 4096-bit RSA key, ID CB86A866E870EE00, created 2016-04-06
# ▶ INFO Exported new key to the local GPG keychain
```## Set up Git to sign all commits
```sh
$ gpg --list-secret-keys --keyid-format LONG
# /Users/pstadler/.gnupg/secring.gpg
# ----------------------------------
# sec 4096R/E870EE00 2016-04-06 [expires: 2032-04-02]
# uid Patrick Stadler
# ssb 4096R/F9E3E72E 2016-04-06$ git config --global user.signingkey E870EE00
$ git config --global commit.gpgsign true
```## Add public GPG key to GitHub
```sh
$ open https://github.com/settings/keys
# Click "New GPG key"# We can then use `export` with the `-q` or query flag to match on our key (the first 16 characters should do..)
$ keybase pgp export -q CB86A866E870EE00 | pbcopy # copy public key to clipboard
# Paste key, save
```## Import key to GPG on another host
```sh
$ keybase pgp export
# ▶ WARNING Found several matches:
# user: Patrick Stadler
# 4096-bit RSA key, ID CB86A866E870EE00, created 2016-04-06# user: keybase.io/ps
# 4096-bit RSA key, ID 31DBBB1F6949DA68, created 2014-03-26$ keybase pgp export -q CB86A866E870EE00 | gpg --import
$ keybase pgp export -q CB86A866E870EE00 --secret | gpg --allow-secret-key-import --import
```After importing you probably want to locally trust your own key, otherwise you will see
`gpg: WARNING: This key is not certified with a trusted signature!` when running `git log --show-signature`.```
$ gpg --edit-key CB86A866E870EE00
gpg> trustPlease decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)1 = I don't know or won't say
2 = I do NOT trust
3 = I trust marginally
4 = I trust fully
5 = I trust ultimately
m = back to the main menuYour decision? 5
Do you really want to set this key to ultimate trust? (y/N) ygpg> quit
```## Troubleshooting: `gpg failed to sign the data`
If you cannot sign a commit after running through the above steps, and have an error like:
```sh
$ git commit -m "My commit"
# error: gpg failed to sign the data
# fatal: failed to write commit object
```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.
Another solution is set up Git to use GPG program on Windows
```sh
$ git config --global user.signingkey E870EE00
$ git config --global commit.gpgsign true
$ git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
```## Optional: Set as default GPG key
```sh
$ $EDITOR ~/.gnupg/gpg.conf
# Add line:
default-key E870EE00
```## 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:
```sh
git config --global gpg.program $(which gpg)
```## Optional: Disable TTY
If you have problems with making autosigned commits from IDE or other software add no-tty config
```sh
$ $EDITOR ~/.gnupg/gpg.conf
# Add line:
no-tty
```## 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.
```sh
$ $EDITOR ~/.profile # or other file that is sourced every time
# Paste these lines
GPG_TTY=$(tty)
export GPG_TTY
```## 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:
```sh
$ brew install pinentry-mac
```Set up the agent:
```sh
$ $EDITOR ~/.gnupg/gpg-agent.conf
# Paste this line:
pinentry-program /usr/local/bin/pinentry-mac
```Now `git commit -S`, it will ask your password and you can save it to macOS
keychain.![pinentry](img/pinentry.png)
### 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:
```sh
$ brew uninstall pinentry-mac
```Now install the GPG Suite versions, available from [gpgtools.org](https://gpgtools.org/#gpgsuite), or from brew by running:
```sh
$ brew install --cask gpg-suite
```Once installed, open Spotlight and search for "GPG Suite", or open system preferences and select "GPG Suite"
Select the Default Key if it is not already selected, and ensure "Store in OS X Keychain" is checked:
![gpg preferences](img/gpg-preferences.png)
The `gpg-agent.conf` is different from Method 1:
Set up the agent:
```sh
$ $EDITOR ~/.gnupg/gpg-agent.conf
# GPG Suite should pre-populate with something similar to the following:
default-cache-ttl 600
max-cache-ttl 7200
```### Testing without a Git Commit
While a full end-to-end test by committing something to git will confirm for sure if things are working, a quick thing you can check is:
```
echo "test" | gpg --clearsign
```This will output something like this if everything goes well:
```
$ echo "test" | gpg --clearsign
gpg: WARNING: server 'gpg-agent' is older than us (2.2.40 < 2.4.0)
gpg: Note: Outdated servers may lack important security fixes.
gpg: Note: Use the command "gpgconf --kill all" to restart them.
gpg: using "9DAC53FB18AB8C5DF0E2AA5B330CB62AE334C5E2" as default secret key for signing
gpg: problem with fast path key listing: IPC parameter error - ignored
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256test
-----BEGIN PGP SIGNATURE-----iQEzBAEBCAAdFiEEmpcZZDDypeoq25Aer4d9fatgnzQFAmPmbXEACgkQr4d9fatg
nzQ/RAf9Elo6RUbb1xWdyPVHqS6Eq67eWmbJ62WriI+2ldMjj8lZp4XtcZ0KzXnO
0U4moVhZyQqBQ1syDC8UNXsTI7pzbRuZ1dzs5tjo+6UuqGfzpgurvw//3L/LxujJ
5asFq//sDNLCHFUAFDbmuWqfcMqpp/KqtaJr8EuCSb/3HSy4J8lMNGyQ4wmpQs5U
Qr5IPLq07NQrOQC3d4vXOmWqY9EZYeSbf0QWCMiErHLxm/jQY+TP88lNre99GmED
4mAD2+I5wd33MizbjfTSH/RAeT5MdLwiBzc6kVjxu4BWusPmdUgLs7vPuP3qeqMQ
q9VnL6mMsaFm0rKnID/MoOPtaghgSA==
=1T8z
-----END PGP SIGNATURE-----
```