Restore SSH Agent connection when attaching to existing tmux or screen session

When you use ssh agent, tmux or screen session gets it from environment variable SSH_AUTH_SOCK. Variable keeps path to socket, that was created for this connection. You close connection and create new one, then you attach to saved session. Now ssh to other servers from shells in this session won’t work, because it has old SSH_AUTH_SOCK value. Here is workaround to fix it:

.bashrc:

if [ -n "$SSH_AUTH_SOCK" -a "$SSH_AUTH_SOCK" != "$HOME/.ssh/auth_sock" ]; then
		ln -sf $SSH_AUTH_SOCK $HOME/.ssh/auth_sock \
		&& export SSH_AUTH_SOCK=$HOME/.ssh/auth_sock
fi


License: This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License Share: share on reddit share on hacker news share on facebook share on twitter share on linkedin share on slashdot

No comments

You today

Comments are closed