Skip to content

Instantly share code, notes, and snippets.

@hostberg
Created March 2, 2018 18:26
Show Gist options
  • Save hostberg/21348d683dca1459c7fa4f7a0b3adeb7 to your computer and use it in GitHub Desktop.
Save hostberg/21348d683dca1459c7fa4f7a0b3adeb7 to your computer and use it in GitHub Desktop.
Signing commits using GPG (macOS High Sierra)

Signing commits using GPG (macOS High Sierra)

Step 1: Install software

brew install gpg2 gpg-agent pinentry-mac       

Step 2: Update ~/.gnupg/gpg-agent.conf

pinentry-program /usr/local/bin/pinentry-mac

Step 3: Update ~/.gnupg/gpg.conf

use-agent

Step 4: Update ~/.bashrc or ~/.zshrc

export GPG_TTY="tty"

Step 5: Restart your Terminal or source your ~/.*rc file

Step 6: Create your GPG Key

Use "RSA and RSA" and "4096" parameters.

gpg --full-gen-key

Step 7: Update the permissions on ~/.gnupg directory

chmod 700 ~/.gnupg

Step 8: Get your GPG key ID

~ gpg --list-secret-keys --keyid-format LONG
/Users/username/.gnupg/pubring.kbx
--------------------------------
sec   rsa4096/%GPG_key_ID% 2018-01-01 [SC]
      1010101010101010101010101010101010101010
uid                 [ultimate] User Name <username@example.com>
ssb   rsa4096/1010101010101010 2018-01-01 [E]

%GPG_key_ID% is your GPG key ID

Step 9: Get your GPG key

gpg --armor --export %GPG_key_ID%

Copy your GPG key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK----- and ending with -----END PGP PUBLIC KEY BLOCK----- to https://github.com/settings/keys

Step 10: Update ~/.gitconfig

[log]
    showSignature = true
[commit]
    gpgsign = true
[gpg]
    program = /usr/local/bin/gpg
[user]
    name = User Name
    email = username@example.com
    signingkey = %GPG_key_ID%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment