I searched and didn't find, and had to figure stuff out... I hope to save you the trouble.

Thursday, April 23, 2009

Automatically start ssh-agent

The following in my .bashrc starts ssh-agent and adds keys automatically whenever I open a shell, if it's not already running:

# Check PS1 to determine if it's a login shell
if [ "$PS1" ]; then
SSH_ENV=$HOME/.ssh/env-$HOSTNAME
if [ -f "$SSH_ENV" ]; then
source $SSH_ENV > /dev/null
fi

ps $SSH_AGENT_PID 2> /dev/null 1>&2
if [ $? != 0 ]; then
echo "$(date) : Starting SSH agent on $HOSTNAME" | tee -a $HOME/.ssh/agent.log
ssh-agent > $SSH_ENV
chmod 600 $SSH_ENV
source $SSH_ENV
ssh-add
fi
fi

No comments:

Post a Comment

Followers