Created
July 20, 2012 05:37
-
-
Save orita/3148887 to your computer and use it in GitHub Desktop.
ssh-agent for bash_profile and bash_logout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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