Using gpg-agent on macOS Sierra

There are many ways to configure this beast. This is one of them. In newer versions of gnupg the option --write-env-file has been removed. If you have a problem with gpg-agent not working across multiple shells this is likely the issue; you're running a newer version of gnupg.

First install [email protected] and pinentry-mac from homebrew. We're using pinentry-mac so you get a nice little graphical input when you need to enter your key. You probably shouldn't store this passphrase in your local keychain.

brew install [email protected] pinentry-mac
# Enables GPG to find gpg-agent
use-standard-socket

# Connects gpg-agent to the OSX keychain via the brew-installed
# pinentry program from GPGtools. This is the OSX 'magic sauce',
# allowing the gpg key's passphrase to be stored in the login
# keychain, enabling automatic key signing.
pinentry-program /usr/local/bin/pinentry-mac

# Optional, cache the keys for some time so you don't have to enter
# your passphrase so often.
# default-cache-ttl 7200
# max-cache-ttl 7200
# Launch gpg-agent if it's not already running
gpgconf --launch gpg-agent

# Optional, when signing git commits
# export GPG_TTY=$(tty)