summaryrefslogtreecommitdiff
path: root/_posts
diff options
context:
space:
mode:
authortekkub <tekkub@gmail.com>2010-11-07 02:42:37 -0700
committertekkub <tekkub@gmail.com>2010-11-07 02:42:37 -0700
commit8feab31306e3e9f34be80224b0f0a692c4037152 (patch)
tree043e33ee5e9d8623331d8df61173d3d82e53e208 /_posts
parentb2ebfe1c863c0fa453a66a05df7099eac1e23a40 (diff)
parent8aacd9ef928015dc34c0a1a3c66eab53741974d3 (diff)
Merge branch 'gh-pages' of git://github.com/Midnighter/help.github.com into gh-pages
Conflicts: _posts/2009-09-03-working-with-key-passphrases.textile
Diffstat (limited to '_posts')
-rw-r--r--_posts/2009-09-03-working-with-key-passphrases.textile54
1 files changed, 38 insertions, 16 deletions
diff --git a/_posts/2009-09-03-working-with-key-passphrases.textile b/_posts/2009-09-03-working-with-key-passphrases.textile
index 3758c16..988e66b 100644
--- a/_posts/2009-09-03-working-with-key-passphrases.textile
+++ b/_posts/2009-09-03-working-with-key-passphrases.textile
@@ -35,27 +35,49 @@ 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"
+<pre>
+SSH_ENV="$HOME/.ssh/environment"
+# start the ssh-agent
function start_agent {
- echo "Initializing new SSH agent..."
- /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
- echo succeeded
- chmod 600 "${SSH_ENV}"
- . "${SSH_ENV}" > /dev/null
- /usr/bin/ssh-add;
+ echo "Initializing new SSH agent..."
+ # spawn ssh-agent
+ ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV
+ echo succeeded
+ chmod 600 $SSH_ENV
+ . $SSH_ENV > /dev/null
+ ssh-add
}
-# Source SSH settings, if applicable
-if [ -f "${SSH_ENV}" ]; then
- . "${SSH_ENV}" > /dev/null
- #ps ${SSH_AGENT_PID} doesn't work under cygwin
- ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
- start_agent;
- }
+# test for identities
+function test_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 [ $? -eq 2 ];then
+ start_agent
+ fi
+ fi
+}
+
+# check for running ssh-agent with proper $SSH_AGENT_PID
+ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
+if [ $? -eq 0 ]; then
+ test_identities
+# if $SSH_AGENT_PID is not properly set, we might be able to load one from
+# $SSH_ENV
else
- start_agent;
-fi</pre>
+ . $SSH_ENV > /dev/null
+ ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
+ if [ $? -eq 0 ]; then
+ test_identities
+ 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.