Skip to content

Instantly share code, notes, and snippets.

@apenney
Created May 1, 2015 13:43
Show Gist options
  • Save apenney/992977b996b84dc26edc to your computer and use it in GitHub Desktop.
Save apenney/992977b996b84dc26edc to your computer and use it in GitHub Desktop.
#!/bin/bash
# http://techblog.appnexus.com/2011/managing-ssh-sockets-in-gnu-screen/
# https://gist.github.com/martijnvermaat/8070533
# http://stackoverflow.com/questions/21378569/how-to-auto-update-ssh-agent-environment-variables-when-attaching-to-existing-tm
# Fix SSH auth socket location so agent forwarding works with screen.
if test "$SSH_AUTH_SOCK" ; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock.$(hostname)
fi
# Don't break x11 Forwarding:
# Taken from the sshd(8) manpage.
if read proto cookie && [ -n "$DISPLAY" ]; then
if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then
# X11UseLocalhost=yes
echo add unix:`echo $DISPLAY |
cut -c11-` $proto $cookie
else
# X11UseLocalhost=no
echo add $DISPLAY $proto $cookie
fi | xauth -q -
fi
###
tmux.conf
# fix ssh agent when tmux is detached
set -g update-environment -r
setenv -g SSH_AUTH_SOCK $HOME/.ssh/ssh_auth_sock.$HOSTNAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment