Skip to content

Instantly share code, notes, and snippets.

@gyng
Last active October 26, 2018 07:12
Show Gist options
  • Save gyng/0723875ee79131ef18a3f2aaeca2b4cb to your computer and use it in GitHub Desktop.
Save gyng/0723875ee79131ef18a3f2aaeca2b4cb to your computer and use it in GitHub Desktop.
Mac OS guide to signing git commits with GPG

Mac OS guide to signing git commits with GPG

Tested on Mojave (10.14)

  1. Install gnupg and the mac integration

    brew install pinentry-mac
    brew install gpg
    
  2. Configure gpg to use pinentry-mac

    which pinentry-mac
    vim ~/.gnupg/gpg-agent.conf
    

    Add this to gpg-agent.conf and save it

    pinentry-program /usr/local/bin/pinentry-mac
    
  3. Restart gpg-agent

    gpgconf --kill gpg-agent
    
  4. Get your key ID (3AA5C...BD2 in this example)

    $ 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. Tell git about it

    git config --global user.signingkey 3AA5C34371567BD2
    
  6. Sign commits with your key

    git commit -S -m your commit message
    
  7. Setup autosign if so desired

    git config commit.gpgsign true
    

Troubleshooting

Try the following:

  • Restart to get pinentry-mac to work
  • Set your git username/email to be the one used in the key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment