Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

statico (5018)

AOL IM: eisforian (Add Buddy, Send Message)


Co-author of Perl Testing: A Developer's Notebook []

Journal of statico (5018)

Tuesday October 11, 2005
10:20 PM

fixing screen and ssh-agent

[ #27127 ]

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:

  • I should be able to run a command, say latestssh, to reattach my current SSH agent to the screen window
  • New screen windows should pick up on the new agent immediately

The Solution

A shell snippet (Zsh, but easily portable):

local agentdir=~/.latestssh
local agentfile=$agentdir/$
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

# ...existing windows can run this alias
alias latestssh="source $agentfile; ls \$SSH_AUTH_SOCK"

# windows get it automatically
if [ -n "$STY" ]; then
    source $agentfile

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • yes I'd very much like to know where in the whole process your script gets worked into the flow -- you didn't mention and I'm (apparently) not savvy enough to grok where I should do it. :)

    Have I mentioned that you rock? heh
    • 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.
      qw(Ian Langworth)