Skip to content

Commit

Permalink
fix(ssh-agent): if ssh id_rsa exist
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Aug 11, 2019
1 parent 4cb39e7 commit dc31a76
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions 1bash.d/ssh-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@ then
source $SSH_AGENT_INFO
fi

if ssh-add -l > /dev/null
if [[ -f ~/.ssh/id_rsa ]]
then
echo 'ssh agent identify key is loaded!'
else
if [ ! -z $SSH_AGENT_PID ]
then
# echo 'Kill the agent'
ssh-agent -k > /dev/null || echo 'Cannot kill ssh-agent'
fi
if [ -e $SSH_AUTH_SOCK ]
then
# echo 'Remove agent socket'
rm -f $SSH_AUTH_SOCK || echo 'Cannot remove agent socket! ($SSH_AUTH_SOCK)'
fi
if [[ -e $SSH_AGENT_INFO ]]

if ssh-add -l > /dev/null
then
# echo 'Remove agent info'
rm -f $SSH_AGENT_INFO || echo 'Cannot remove agent info! ($SSH_AGENT_INFO)'
echo 'ssh agent identify key is loaded!'
else
if [ ! -z $SSH_AGENT_PID ]
then
# echo 'Kill the agent'
ssh-agent -k > /dev/null || echo 'Cannot kill ssh-agent'
fi
if [ -e $SSH_AUTH_SOCK ]
then
# echo 'Remove agent socket'
rm -f $SSH_AUTH_SOCK || echo 'Cannot remove agent socket! ($SSH_AUTH_SOCK)'
fi
if [[ -e $SSH_AGENT_INFO ]]
then
# echo 'Remove agent info'
rm -f $SSH_AGENT_INFO || echo 'Cannot remove agent info! ($SSH_AGENT_INFO)'
fi

echo 'Start ssh-agent'
ssh-agent -a "$SSH_AUTH_SOCK" -s > $SSH_AGENT_INFO
ssh-add
fi

echo 'Start ssh-agent'
ssh-agent -a "$SSH_AUTH_SOCK" -s > $SSH_AGENT_INFO
ssh-add
fi
fi

0 comments on commit dc31a76

Please sign in to comment.