using gpg-agent between different sessions
gpg
does not look for the socket (this is different with the new version 2.1) but for the environment variable GPG_AGENT_INFO
. This is not set on log in. That is the problem. Obviously you have the option use-standard-socket
in gpg-agent.conf
so that the socket name is always the same.
You should set the variable in a login script run a simple script afterwards which checks whether gpg-agent
is running:
export GPG_AGENT_INFO=/path/to/your/HOME/.gnupg/S.gpg-agent:42:1
gpg-connect-agent /bye &>/dev/null || gpg-agent --daemon &>/dev/null
That is the part for using gpg
. For SSH you also need SSH_AUTH_SOCK
. The easiest way to get both variables set is to add the line
write-env-file "${HOME}/.gpg-agent-info
to the config file gpg-agent.conf
and to run this script after the above:
. "${HOME}/.gpg-agent-info"
export SSH_AUTH_SOCK
This is explaned in the gpg-agent
man page.