Cache GPG passphrase for git signing on Mac

Viewed 2349

There is already a more generic thread on the topic, Remember GPG password when signing git commits, but the answer there doesn't work for me. My environment is:

  • Mac (macOS@10.15.7)
  • Bash (the default that comes with macOS)
  • Git v2.27.0
  • GnuPG v2.2.20 (libgcrypt 1.8.5)

I installed GnuPG via Homebrew and wrote the following settings into the ~/.gnupg/gpg-agent.conf file:

default-cache-ttl 1209600 # 14 days
max-cache-ttl 31536000 # 1 year

But the cache isn't applied. Every ten minutes or so after I do a git commit, gpg prompts me to input the password again.

This is my global .gitignore file:

[commit]
    gpgSign = true

What am I missing?

1 Answers

In my personal setup I have added the signingkey to the user section.

[user]
name = "Marco Franssen"
email = "marco@my-email.com"
signingkey = 63B0C3B53E26....

[commit]
gpgSign = true

Furthermore I have the following plugins in oh-my-zsh. (~/.zshrc)

plugins=(git keychain gpg-agent)

zstyle :omz:plugins:keychain agents ssh,gpg
zstyle :omz:plugins:keychain identities id_rsa 63B0C3B53E2....

This plugin boots an agent for my ssh and gpg keys.

Furthermore I have added the following file

$ cat ~/.gnupg/gpg-agent.conf
default-cache-ttl 3600

For Bash you might add the following to your ~/.bashrc.

https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/gpg-agent/gpg-agent.plugin.zsh

Related