How to make `git commit --gpg-sign` remember the SSH key password until I log out?
Dec 7, 11:28pm
To make git commit --gpg-sign remember your SSH key password (or more accurately, your GPG key passphrase) until you log out, you need to use a credential helper or agent that caches your passphrase. Here’s how you can achieve this:
1. Use gpg-agent to Cache Your Passphrase
gpg-agent is the standard way to cache GPG passphrases. It can be configured to remember your passphrase for a set period or until you log out.
Steps:
Edit or create the gpg-agent configuration file:
Open or create ~/.gnupg/gpg-agent.conf and add the following lines:
text
default-cache-ttl 34560000
max-cache-ttl 34560000
default-cache-ttl sets the default cache time (in seconds). 34560000 is roughly 1 year, but you can set it to 0 to cache until logout.
max-cache-ttl sets the maximum cache time.
Restart gpg-agent:
Run the following command to restart the agent:
You will be prompted for your passphrase once, and it will be cached until you log out.
Configure Git to use SSH for GPG signing:
If you are using SSH for GPG signing (e.g., with gpg.format=ssh), ensure your Git config is set up correctly: