blog.zapster.cc

random notes...

resurrecting ssh-agent

There are many articles and blog entries out there about ssh-agent and what is the best way of using it. The start script I am using is a slightly modified version of the code proposed in this Cygwin mailing list post.

It fixes an issue that occurs if the home directory is shared among different machines (e.g. nfs mount).

(sshagentrc) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
SSHAGENT=/usr/bin/ssh-agent
SSHADD=/usr/bin/ssh-add
SSHAGENTARGS="-s"


SSH_ENV=$HOME/.ssh/environment.`hostname`

function start_agent {
    echo "Initialising new SSH agent..."
    $SSHAGENT $SSHAGENTARGS | sed 's/^echo/#echo/' > ${SSH_ENV}
    echo succeeded
    chmod 600 ${SSH_ENV}
    . ${SSH_ENV} >> /dev/null
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
     . ${SSH_ENV} > /dev/null
     ps ${SSH_AGENT_PID} | grep ssh-agent > /dev/null || {
         start_agent;
     }
else
     start_agent;
fi

Comments