How to update environment automatically when close the ssh connection forcelly and reconnect via ssh and reattach the tmux session?

393 views
Skip to first unread message

Isaac Ge

unread,
Jun 25, 2018, 4:20:32 AM6/25/18
to tmux-...@googlegroups.com
I know there is a feature called "update-environmen", it will update "SSH_AUTH_SOCK" automatically if I deattach the tmux session, then close the ssh connection, then reconnect to the remote machine via ssh, then attach the tmux session finally.

However, I am used to close the whole virtual termite window immediately so that I close the ssh connection forcely too. Then reconnect to the remote machine via ssh, then attach the tmux session, but the latter does not update "SSH_AUTH_SOCK" automatically, even I put "set-option -g update-environment" to the `.tmux.conf` and reload the config manually. The relative StackOverflow have disscussed this question too: https://stackoverflow.com/questions/21378569/how-to-auto-update-ssh-agent-environment-variables-when-attaching-to-existing-tm#comment74036952_23187030

I have tried to put the following to the `.zshrc`:

```
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 
```

However, it will update SSH_AUTH_SOCK automalically in the new created zsh window in the tmux session, it does not affect the existed zsh window in the tmux session.

Nicholas Marriott

unread,
Jun 25, 2018, 1:19:55 PM6/25/18
to Isaac Ge, tmux-...@googlegroups.com
There is no sensible way for tmux to modify the environment in processes
that are already running.

You can run something like:

eval `tmux showenv -s SSH_AUTH_SOCK`

In your existing shells after reattaching (assuming you have
SSH_AUTH_SOCK in update-environment - it is there by default).


On Mon, Jun 25, 2018 at 04:20:21PM +0800, Isaac Ge wrote:
> I know there is a feature called "update-environmen", it will update
> "SSH_AUTH_SOCK" automatically if I deattach the tmux session, then close
> the ssh connection, then reconnect to the remote machine via ssh, then
> attach the tmux session finally.
> However, I am used to close the whole virtual termite window immediately
> so that I close the ssh connection forcely too. Then reconnect to the
> remote machine via ssh, then attach the tmux session, but the latter does
> not updateA "SSH_AUTH_SOCK" automatically, even I put "set-option -g
> update-environment" to the `.tmux.conf` and reload the config manually.
> The relative StackOverflow have disscussed this question
> too:A https://stackoverflow.com/questions/21378569/how-to-auto-update-ssh-agent-environment-variables-when-attaching-to-existing-tm#comment74036952_23187030
> I have tried to put the following to the `.zshrc`:
> ```
> if [-S "$SSH_AUTH_SOCK"] && [ ! -h "$SSH_AUTH_SOCK" ]; thenA
> A A ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sockA
> fiA
> export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sockA
> ```
>
> However, it will update SSH_AUTH_SOCK automalically in the new created zsh
> window in the tmux session, it does not affect the existed zsh window in
> the tmux session.
>
> --
> You received this message because you are subscribed to the Google Groups
> "tmux-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tmux-users+...@googlegroups.com.
> To post to this group, send email to tmux-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages