Mention dotfiles management in the gpg-agent post.
[blog.git] / posts / gpg-agent.mdwn
1 The 2.X branch of [[GnuPG]] comes with [gpg-agent][] for caching
2 passphrases.  The documentation is good, but here are my notes
3 outlining my usual usage.
4
5 Add the following to your `~/.bashrc` (see [[dotfiles]] for fancy
6 dotfiles maintenance):
7
8     if [ -f "${HOME}/.gnupg/agent-info" ]; then
9       source "${HOME}/.gnupg/agent-info"
10     fi
11
12 Start the agent with
13
14     $ GPG_TTY=$(tty)
15     $ gpg-agent --daemon --write-env-file "${HOME}/.gnupg/agent-info"
16     $ echo "GPG_TTY='${GPG_TTY}'; export GPG_TTY" >> "${HOME}/.gnupg/agent-info"
17     $ source "${HOME}/.gnupg/agent-info"
18
19 The `GPG_TTY` bit will spawn the `pinentry` call in the designated
20 TTY.  This avoids troublesome issues like pinentry clobbering [[Mutt]]
21 if they are both using ncurses.
22
23 I didn't like any of the pinentry programs available on my system, so
24 I wrote my own: [[pinentry.py]].  To use my script, save it somewhere
25 on your system and add a line like the following to your
26 `~/.gnupg/gpg-agent.conf`.
27
28     pinentry-program /path/to/pinentry.py
29
30 When you are done with the agent, kill it with
31
32     $ killall gpg-agent
33     $ rm -f "${HOME}/.gnupg/agent-info"
34
35 [gpg-agent]: http://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html
36
37 [[!tag tags/linux]]
38 [[!tag tags/tools]]