summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Beber <m.beber@jacobs-university.de>2010-08-11 15:22:17 +0200
committerMoritz Beber <m.beber@jacobs-university.de>2010-08-11 15:22:17 +0200
commiteedf0d0871a158c4254515c09ec2eca7b43a32dc (patch)
tree9d8060b074d385bab65fb189e4d3e9728b2f59d4
parent3aedad7490335796eb80bd549b9f526a699f374d (diff)
Straightened out some flaws in the behaviour.
The idea is to have a single ssh-agent instance that holds all the keys. Checking and spawning of ssh-agents should be consistent now.
-rw-r--r--_posts/2009-09-03-working-with-key-passphrases.textile23
1 files changed, 13 insertions, 10 deletions
diff --git a/_posts/2009-09-03-working-with-key-passphrases.textile b/_posts/2009-09-03-working-with-key-passphrases.textile
index 11fd037..604221e 100644
--- a/_posts/2009-09-03-working-with-key-passphrases.textile
+++ b/_posts/2009-09-03-working-with-key-passphrases.textile
@@ -36,29 +36,32 @@ h2. Auto-launching ssh-agent on msysgit
You can run @ssh-agent@ automatically when you open bash by adding the following to your @~/.profile@ or @~/.bashrc@ file:
<pre>
-SSH_ENV="$HOME/.ssh/environment"
# automatically start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
- ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
+ # spawn ssh-agent
+ eval `ssh-agent` > /dev/null
echo succeeded
- chmod 600 "${SSH_ENV}"
- . "${SSH_ENV}" > /dev/null
ssh-add
}
-# check for running ssh-agent
-ps -ef | grep ${SSH_AGENT_PID} | grep -v grep > /dev/null
+# check for running ssh-agent with proper $SSH_AGENT_PID
+ps -ef | grep $SSH_AGENT_PID | grep -v grep > /dev/null
if [ $? -eq 0 ]; then
- # test whether standard identities have been added to
- # the agent already
- ssh-add -l | grep "agent has no identities"
+# test whether standard identities have been added to the agent already
+ ssh-add -l | grep "The agent has no identities" > /dev/null
if [ $? -eq 0 ]; then
ssh-add
+ # $SSH_AUTH_SOCK broken so we start a new proper agent
+ if [ $? -ne 0 ];then
+ start_agent
+ fi
fi
+# if $SSH_AGENT_PID is not properly set, the socket is probably neither better
+# to start a new agent
else
start_agent
-fi
+fi
</pre>
p(. *Note:* If you don't use the default key names, or store your keys in a different path, you will need to add the path to the @/usr/bin/ssh-add@ line so that ssh knows where to find your key.