The Problem
I use Screen to leave programs running and an SSH key agent to shell between machines and use CVS without reentering my password. Disconnnecting from the server that the screen session is running on removes the connection to the SSH agent.
What should happen:
latestssh, to reattach my current SSH agent to the screen window
The Solution
A shell snippet (Zsh, but easily portable):
local agentdir=~/.latestssh
local agentfile=$agentdir/$HOST.sh
mkdir -p $agentdir
chmod 0700 $agentdir >/dev/null
if [ -n "$SSH_AUTH_SOCK" -a -z $STY ]; then
echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >$agentfile
chmod 0600 $agentfile >/dev/null
fi
# ...existing windows can run this alias
alias latestssh="source $agentfile; ls \$SSH_AUTH_SOCK"
# ...new windows get it automatically
if [ -n "$STY" ]; then
source $agentfile
fi
Re:ooh that annoys me...
statico on 2005-10-15T04:23:25
That snippet is simply plopped into my.zshrc file. New screen windows magically receive the new agent, and I can run the "latestssh" command in existing windows.
If you're wondering how to set up an SSH key agent, there are lots of tutorials out there. I use the widely-distributed "keychain" utility as well.