The intersection of anything computing with nirvana is typically the empty set, but every once in a while you bump into that little productivity tweak that makes a big difference.
Yesterday at work I finally had my worn out and beat up PowerBook replaced with a shiny new MacBook Pro. Moving over to it took maybe an hour - half of that copying my data over from the old laptop using a direct FireWire connection. The entire migration experience in itself is well worth the price of admission.
I was doing my final tweaks and finally decided I was tired of firing up a ssh-agent and authenticating in each terminal window. I usually have a handful of terminal windows open, so once I've fired my passphrase off a handful of times (once for every window) I am ready for action. Not terrible, but certainly inconvenient. It was time to put and end to that. (It's funny how inertia is so strong - I should've taken the 10 minutes to figure this out eons ago).
I found a few options - piles of zany scripts that didn't quite provide a solution and a couple of GUI applications. I wasn't interested in anything GUI, so scratch that. (Why? I dunno, that's just me. Also, I didn't want to play catch up with beta 0.1 releases of homegrown applications.). Anyhow, I finally found a very nice solution, courtesy of a post on macosxhints.com:
#############################################
function sshagent () {
SSHAGENT_ENVFILE=~/.ssh/ssh-agent.sh
if [ "${1}" = "stop" ]; then
echo -n "SSH-AGENT: "
eval `ssh-agent -k`
if [ -e "${SSHAGENT_ENVFILE}" ]; then
rm ${SSHAGENT_ENVFILE}
fi
else
echo -n "SSH-AGENT: "
if [ -e "${SSHAGENT_ENVFILE}" ]; then
source "${SSHAGENT_ENVFILE}"
else
ssh-agent -s > ${SSHAGENT_ENVFILE}
source "${SSHAGENT_ENVFILE}"
ssh-add ~/.ssh/id_dsa ~/.ssh/id_rsa
fi
fi
}
sshagent start
##############################################
Simply drop this into your .bash_profile and voila! Fire up and authenticate to ssh-agent once and all other Terminal.app windows will use the same ssh-agent.
Today was a better day because of this simple change. Note to self: don't put off investigating how to get that annoying little pebble out of your shoe. You'll be much more comfortable, if not happier, walking through the day.
Comments