The first thing my .bash_aliases file does on login is to check if I’m running ssh-agent and if so, stick that into my shell environment. If not, kick it up, and update a reminder to it. This morning I found a flaw in that, so I believe this is the fix.
4 export SSH_RECENT="$HOME/.ssh/recent" 5 [ -f "$SSH_RECENT" ] && eval `cat $SSH_RECENT` 6 RUNNING_AGENTS=0 7 if [ ! -z "$SSH_AGENT_PID" ] 8 then 9 RUNNING_AGENTS=`pgrep -u $(id -u) ssh-agent | grep $SSH_AGENT_PID | wc -l` 10 fi 11 if [ $RUNNING_AGENTS -lt 1 -a $UID -ne 0 ] 12 then 13 eval `ssh-agent` 14 echo "export SSH_AGENT_PID=$SSH_AGENT_PID" > $SSH_RECENT 15 echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $SSH_RECENT 16 fi 17 [ `ssh-add -l | fgrep -v ' no ' | wc -l` -eq 0 ] && ssh-add