When you SSH into a remote host with agent forwarding (ssh -A) and start a tmux session, everything works fine. But when you disconnect and reconnect later, SSH agent forwarding stops working inside your existing tmux session.
Each time you SSH in, a new authentication socket is created at a path like /tmp/ssh-XXXXXX/agent.12345. When you start tmux, it captures this socket path in SSH_AUTH_SOCK.
When you disconnect and reconnect:
- Your new SSH session creates a new socket (e.g.,
/tmp/ssh-YYYYYY/agent.67890) - tmux updates its environment with the new socket
- But your existing shell sessions inside tmux still point to the old, now-invalid socket
# Inside tmux after reconnecting
$ ssh-add -l
Could not open a connection to your authentication agent.
$ echo $SSH_AUTH_SOCK
/tmp/ssh-rT2D758KaF/agent.458032 # Old socket
$ tmux show-environment | grep SSH_AUTH_SOCK
SSH_AUTH_SOCK=/tmp/ssh-4ygs8ipXS2/agent.468415 # New socketAdd
# Fix SSH agent forwarding in tmux
if [ -n "$TMUX" ]; then
eval $(tmux show-environment -s SSH_AUTH_SOCK)
fi