Restarting gpg-agent

Michel Messerschmidt lists at
Sun Mar 14 22:16:00 CET 2010

On Sun, Mar 14, 2010 at 12:24:14PM -0700, James Moe wrote:
> Hello,
>   opensuse v11.2, linux x86_64, gpg v2.0.12.
>   The docs at <> cover starting gpg-agent pretty
> well. What is missing is how to re-start it.
>   If gpg-agent is terminated for some reason, or the system is booted,
> the file <> is left behind. Because the file exists, when
> .bashrc is run it detects the file and does not start gpg-agent.
>   Is there some way to:
> 1. Detect if gpg-agent is running. If not, erase <>, or
> 2. Erase <> at boot time.

This works for me (in .bashrc):

export GNUPGHOME="${HOME}/.gnupg"
# check that gpg-agent is executable and enabled in the gpg config
if grep -qs '^[[:space:]]*use-agent' "${GNUPGHOME}/gpg.conf" &&
   test -x ${GPGAGENT}; then
    # always re-read the gpg-agent info file to find the running instance
    if [ -r "${GA_INFO_FILE}" ]; then
        . "${GA_INFO_FILE}"
    # start gpg-agent if no running instance is found
    if test -z "${GPG_AGENT_INFO}" ||
       ! kill -0 `grep GPG_AGENT_INFO ${GA_INFO_FILE} | cut -d: -f 2 -` 2>/dev/null; then
        # enable ssh support by default if set in global Xsession options
        if grep -qs '^[[:space:]]*use-ssh-agent' /etc/X11/Xsession.options; then
        # execute gpg-agent and export environment variables
        eval $(${GPGAGENT} --daemon ${GA_SSH} --sh --write-env-file=${GA_INFO_FILE})
    export GPG_AGENT_INFO
    export SSH_AUTH_SOCK
    export SSH_AGENT_PID


More information about the Gnupg-users mailing list