Skip to content

Instantly share code, notes, and snippets.

@thwarted
Created March 28, 2011 08:33
Show Gist options
  • Save thwarted/890156 to your computer and use it in GitHub Desktop.
Save thwarted/890156 to your computer and use it in GitHub Desktop.
the script I use to restore my ssh-agent settings to running screen sessions
#!/bin/bash
if [ "$TERM" != "screen" ]; then
# if the auth socket variable is empty, don't do anything
if [ ! -z "$SSH_AUTH_SOCK" ]; then
# include USER to protect against shared HOME directories (rare)
NEWSOCK=$HOME/.agent-sshscreen-$USER.sock
if [ "$SSH_AUTH_SOCK" != "$NEWSOCK" ]; then
# test if the auth sock we have is actually working
# don't link to a dead socket
if ssh-add -l > /dev/null 2>&1; then
/bin/ln -sf $SSH_AUTH_SOCK $NEWSOCK
export SSH_AUTH_SOCK=$NEWSOCK
fi
fi
fi
exec /usr/bin/screen "$@"
else
echo "can't start up screen inside screen"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment