add ssh-restore.sh
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Wed, 4 Jun 2014 22:17:43 +0000 (15:17 -0700)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Wed, 4 Jun 2014 22:17:43 +0000 (15:17 -0700)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

ssh-restore.sh [new file with mode: 0755]

diff --git a/ssh-restore.sh b/ssh-restore.sh
new file mode 100755 (executable)
index 0000000..1f64256
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+#
+# Update the value of the ~/.ssh/ssh_auth_sock symlink to point to the new
+# active socket.
+#
+# I like to use ssh-agent forwarding plus tmux.  In practice, this means that
+# the first time I start tmux, it automatically knows how to talk to my
+# currently active agent.  But then, when I detach tmux and log out of ssh,
+# that agent goes away.  On my next ssh login, I need to tell tmux about the
+# new agent by updating this symlink.  This script does that.
+#
+
+if [ -S "$SSH_AUTH_SOCK" ] && [ ! -h "$SSH_AUTH_SOCK" ]; then
+    ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
+fi
+export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock