add ssh-restore.sh
[cmccabe-bin] / ssh-restore.sh
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