Skip to content

Instantly share code, notes, and snippets.

@bchiang7
Last active December 15, 2022 07:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bchiang7/47df18319d6507d82a1b3a34fce55dd8 to your computer and use it in GitHub Desktop.
Save bchiang7/47df18319d6507d82a1b3a34fce55dd8 to your computer and use it in GitHub Desktop.
Signing GitHub Commits with GPG

Signing GitHub Commits with GPG (Mac)

https://help.github.com/en/articles/managing-commit-signature-verification

  1. Check for existing GPG keys

    gpg --list-secret-keys --keyid-format LONG

    If there is a GPG key, skip to Step 4

  2. Create a GPG key if you don't already have one

    gpg --full-generate-key

    Answer the questions, and use your GitHub email.

  3. Make sure you now have a GPG key

    gpg --list-secret-keys --keyid-format LONG
  4. Copy the GPG key ID. In this example, the GPG key ID is 3AA5C34371567BD2

    $ gpg --list-secret-keys --keyid-format LONG
    /Users/hubot/.gnupg/secring.gpg
    ------------------------------------
    sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
    uid                          Hubot
    ssb   4096R/42B317FD4BA89E7A 2016-03-10
  5. Paste the text below, substituting in your GPG key ID. In this example, the GPG key ID is 3AA5C34371567BD2:

    gpg --armor --export 3AA5C34371567BD2
    # Prints the GPG key ID, in ASCII armor format
  6. Copy your GPG key, beginning with -----BEGIN PGP PUBLIC KEY BLOCK----- and ending with -----END PGP PUBLIC KEY BLOCK-----

  7. Add your GPG key to your GitHub account in settings

    Settings > SSH and GPG Keys > New GPG Key

    Paste your GPG key into the "key" field and save.

  8. Paste the text below, substituting in the GPG key ID, to set your GPG signing key in Git. In this example, the GPG key ID is 3AA5C34371567BD2:

    git config --global user.signingkey 3AA5C34371567BD2
  9. Add this line to your bash/zsh profile

    export GPG_TTY=$(tty)
  10. Tell Git to sign every commit

    git config --global commit.gpgsign true
  11. Add these lines to your ~/.gnupg/gpg-agent.conf to make gpg remember your passphrase using gpg-agent

    default-cache-ttl 34560000
    max-cache-ttl 34560000

    34560000 seconds = 400 days

  12. Restart gpg-agent for changes to take effect

    gpg-connect-agent reloadagent /bye

    If gpg-agent is not running you can start it with this command

    gpg-agent --daemon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment