1

I'm using a long running tmux session on my workstation. Sometimes I have to connect to this workstation by ssh from my laptop. I take my ssh private key stored on a YubiKey with me. Means the Yubikey is connected to the Workstation or to the laptop. To use ssh inside of tmux I have to manage the SSH_AUTH_SOCK environment variable to connect to the right ssh-agent.

for new windows I have already implemented the 'update-environment' solution I found here:

set -ga update-environment "SSH_AUTH_SOCK"

to update the environment of already running sessions I'm looking for any type of shortcut, alias or script.

How can I identify a pid or the tty of the parrent session I'm currently connected to tmux to select the right ssh-agent socked? Or is there a tmux command to update the "SSH_AUTH_SOCK" variable manual?

grunix
  • 11
  • 2

1 Answers1

0

With SSH_AUTH_SOCK in update-environment it will be changed in the session environment when you attach, so you can see it with "tmux showenv SSH_AUTH_SOCK" (note no -g because it is the session environment not the global environment that is changed by update-environment).

So you can look at that and use it to change the environment in any existing pane manually. If you are using a Bourne-style shell it should be as simple as "eval `tmux showenv -s SSH_AUTH_SOCK`".

Also note that SSH_AUTH_SOCK has been in the default update-environment since 2009 so you should not need to change it unless you are using a very very old tmux version.

  • This is a possible solution, but It has the problem that I have to disconnect and re-attach to tmux every time when I'm back at the workstation?! – grunix Aug 28 '19 at 13:25
  • If you don't want to do that you will need to write your own script, you can use the client_tty format to get the ttyname outside tmux (or rather outside its best guess for the current client - IIRC it is the most recently used so should work for you). – Nicholas Marriott Aug 29 '19 at 00:39
  • thank you! Till I can identify the connected client I will use this workaround (including a re-attach): ```bash alias sshclientSock='eval $(/usr/bin/tmux showenv -s SSH_AUTH_SOCK)' ``` Still looking for a solution to identify the current client... – grunix Aug 29 '19 at 07:19