This will prevent the ssh-agent from being started multiple times.
It will also add existing rsa keys to the ssh-agent.
Will also work on linux.
SSH_AUTH_SOCK=~/.ssh/ssh-agent.sock | |
ssh_agent_pid=$(ps -aef | grep ssh-agent | tr -s ' ' | cut -f 3 -d ' ') | |
[ -e ${SSH_AUTH_SOCK} ] && [ -z ${ssh_agent_pid} ] && rm ${SSH_AUTH_SOCK} | |
ssh-add -l 2>/dev/null >/dev/null | |
[ $? -ne 0 ] && ssh-agent -a ${SSH_AUTH_SOCK} 2>/dev/null >/dev/null | |
export SSH_AUTH_SOCK | |
# add existing rsa keys | |
ssh-add ~/.ssh/*_rsa 2>/dev/null >/dev/null |