Last active
March 16, 2018 07:21
-
-
Save Wirone/9dd35ac45c2aadd548ab187fa258aded to your computer and use it in GitHub Desktop.
GPG key and agent for Git commit signing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is working mix of information found on the Internet. | |
Most tutorials mention obsolete --write-env-file, | |
so I use simple eval with whole output redirected to /dev/null | |
in order to silently spawn GPG agent daemon. | |
Had to use test command mentioned above so GPG asked for key's passphrase (only once). | |
Got this working on: | |
- Kubuntu 16.04 | |
- gpg (GnuPG) 1.4.20 | |
- gpg (GnuPG) 2.1.11 | |
- zsh 5.1.1 (x86_64-ubuntu-linux-gnu) | |
Works with PhpStorm (built-in Git support) and GitExtensions (through Mono). | |
CLI command for testing agent: | |
echo "test" | gpg --use-agent -ase -r <YOUR_KEY_ID> | gpg --use-agent | |
echo "test" | gpg2 --use-agent -ase -r <YOUR_KEY_ID> | gpg2 --use-agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.gnupg/gpg-agent.conf | |
default-cache-ttl 28800 | |
max-cache-ttl 28800 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.gnupg/gpg.conf | |
keyserver-options auto-key-retrieve | |
no-tty | |
use-agent | |
default-key <YOUR_KEY_ID> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.zshrc | |
# Make sure GPG Agent is working | |
if test -f ~/.gpg-agent-info && \ | |
kill -0 `cut -d: -f 2 ~/.gpg-agent-info` 2>/dev/null; then | |
export GPG_AGENT_INFO=`cat ~/.gpg-agent-info | cut -c 16-` | |
else | |
eval "$(gpg-agent --daemon --no-grab > /dev/null 2>&1)" | |
fi | |
export GPG_TTY=$(tty) | |
export GPG_AGENT_INFO | |
export GPGKEY=<YOUR_KEY_ID> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment