Configure a single ssh-agent and gpg-agent and use them everywhere


Using this recipe you’ll get a single ssh-agent and a single gpg-agent running for your user and the correct environmental variables will be set everywhere. Just add this code to your ~/.bashrc: [code lang=“bash”]# GPG Agent if [ -x $(which gpg-agent) ] && [ -d “${HOME}/.gnupg” ]; then oldumask=$(umask) umask 0077 pgrep -U $LOGNAME gpg-agent >/dev/null 2>&1 || gpg-agent –daemon –write-env-file “${HOME}/.gnupg/gpg-agent-info” >/dev/null 2>&1 umask $oldumask GPG_TTY=$(tty) export GPG_TTY if [ -r “${HOME}/.gnupg/gpg-agent-info” ]; then . “${HOME}/.gnupg/gpg-agent-info” export GPG_AGENT_INFO fi fi

# SSH Agent if [ -x $(which ssh-agent) ] && [ -d “${HOME}/.ssh” ]; then pgrep -U $LOGNAME ssh-agent >/dev/null 2>&1 || ssh-agent | sed ’s/^echo/#echo/’ > “${HOME}/.ssh/environment” if [ -r “${HOME}/.ssh/environment” ]; then . “${HOME}/.ssh/environment” fi fi [/code]