DEV Community

Jie
Jie

Posted on • Edited on • Originally published at jma.im

Setup GPG for git on macOS

Install gnupg and pinentry-mac

brew install gnupg
brew install pinentry-mac
Enter fullscreen mode Exit fullscreen mode

Generating a GPG key

Github help

Generating key

gpg --full-generate-key
Enter fullscreen mode Exit fullscreen mode

Checking the key

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
Enter fullscreen mode Exit fullscreen mode

Copying the key

In this example, the GPG key ID is 3AA5C34371567BD2

gpg --armor --export 3AA5C34371567BD2 | pbcopy
Enter fullscreen mode Exit fullscreen mode

Load the key for git

vim .gnupg/gpg-agent.conf
Enter fullscreen mode Exit fullscreen mode

add the line

pinentry-program /usr/local/bin/pinentry-mac
Enter fullscreen mode Exit fullscreen mode

Backup and restore

gpg --export-secret-keys KEY_ID > my-private-key.asc
gpg --import my-private-key.asc
Enter fullscreen mode Exit fullscreen mode

Top comments (0)