How to configure gpg to enter passphrase only once per session ?

Reblogging : Because the following has made my life — at the console, and beyond — a lot easier. 😉

How to configure gpg to enter passphrase only once per session

  1. Install gpg-agent and pinentry program :
    sudo apt-get install gnupg-agent pinentry-curses
  2. Add the lines below to ~/.profile. Any POSIX-confirming shell should include this file.

# Invoke GnuPG-Agent the first time we login.
# Does `~/.gpg-agent-info' exist and points to gpg-agent process accepting signals?
if test -f $HOME/.gpg-agent-info && \
    kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null; then
    GPG_AGENT_INFO=`cat $HOME/.gpg-agent-info | cut -c 16-`
    # No, gpg-agent not available; start gpg-agent
    eval `gpg-agent --daemon --no-grab --write-env-file $HOME/.gpg-agent-info`
export GPG_TTY=`tty`

This little script will be activated when you login. If the agent is not running, it will be started. When the agent is started, it shows how to set environment variables in order to connect to it. The script saves these values in ~/.gpg-agent-info, so that when you start another login session the script can setup the variables correctly and thus use the agent.

You will only have to enter your passphrase once per boot. The agent will store your keys in memory, so you don’t have to enter the passphrase again.

Target : Self.

PS : Often, while I’m chasing for solutions — to this, or that problem — I “ forget ” to make notes. Yes — it’s a bad habit — I know. Point being : Me being focused, on fixing what lies in front of me. Which after all, is what I wanted to do.