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:
gpg-agent to Cache Your Passphrasegpg-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.
Edit or create the gpg-agent configuration file:
Open or create ~/.gnupg/gpg-agent.conf and add the following lines:
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:
bashgpgconf --kill gpg-agent gpgconf --launch gpg-agent
Ensure gpg-agent is used by Git:
Add the following to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc):
bashexport GPG_TTY=$(tty)
Then, reload your shell configuration:
bashsource ~/.bashrc # or source ~/.zshrc
ssh-agent for SSH Keys (if applicable)If you are using an SSH key for GPG signing (via ssh-agent), you can also configure ssh-agent to cache your passphrase.
Start ssh-agent and add your key:
basheval "$(ssh-agent -s)" ssh-add ~/.ssh/your_private_key
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:
bashgit config --global gpg.format ssh git config --global user.signingkey ~/.ssh/your_private_key.pub
Test your setup by running:
bashecho "test" | gpg --clearsign
You should not be prompted for your passphrase if the cache is working.
Test a signed Git commit:
bashgit commit --gpg-sign -m "Test signed commit"
gpg-agent~/.gnupg/gpg-agent.confgpgconf --kill gpg-agentdefault-cache-ttl 0ssh-agenteval "$(ssh-agent -s)"This Chat is read-only. Login to resume chatting.