Skip to content

Instantly share code, notes, and snippets.

@orita
Created July 20, 2012 05:37
Show Gist options
  • Save orita/3148887 to your computer and use it in GitHub Desktop.
Save orita/3148887 to your computer and use it in GitHub Desktop.
ssh-agent for bash_profile and bash_logout
cp ~/.bash_profile ~/dot.bash_profile.$$
cat <<'EOF'>> ~/.bash_profile
# ssh-agent
SSH_AUTH_SOCK=~/.ssh/agent.sock
SSH_AUTH_INFO=~/.ssh/ssh-agent-info
#if [ ! -f ${SSH_AUTH_SOCK} ] ; then
# mksock ${SSH_AUTH_SOCK}
#fi
if [ -f ${SSH_AUTH_INFO} ] ; then
source ${SSH_AUTH_INFO}
fi
ssh-add -l >&/dev/null
if [ $? == 2 ] ; then
echo -n "ssh-agent: restart..."
ssh-agent -a ${SSH_AUTH_SOCK} >${SSH_AUTH_INFO}
source ${SSH_AUTH_INFO}
fi
if ssh-add -l >&/dev/null ; then
echo "ssh-agent: Identity is already stored."
else
ssh-add
fi
EOF
cp ~/.bash_logout ~/dot.bash_logout.$$
cat <<'EOF'>> ~/.bash_logout
# ssh-agent
if [ `who | grep -c $USER` -eq 1 ] ; then
ssh-agent -k
fi
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment