SSH-Agent information lost when creating a new window

21 views
Skip to first unread message

Jörg Kastning

unread,
May 19, 2020, 1:35:17 AM5/19/20
to tmux-...@googlegroups.com
Hello tmux-users,

I don't know whether it is some kind of missing feature or I'm just
stupid and don't understand it. So I'm in hope for some help.

My use case:
I'm logging in to my machine via SSH and start the ssh-agent by running
the command `exec ssh-agent bash` and add my private key afterwards.
Next I start tmux which keeps the ssh-agent info in the first window.
I've checked that via `echo $SSH_AUTH_SOCK`.

Now, when I create a new window the ssh-agent information are lost and
`echo $SSH_AUTH_SOCK` returns an empty string.

Is there any way to keep the ssh-agent information?

And of course, thanks for this great piece of software. :-)

Kind regards,
Joerg

Nicholas Marriott

unread,
May 19, 2020, 1:47:45 AM5/19/20
to Jörg Kastning, tmux-...@googlegroups.com
Hi

The way tmux works is that when you start the server the environment
(including SSH_AUTH_SOCK) is copied into the global environment and that
is used for all new panes.

Then by default SSH_AUTH_SOCK is updated from the shell into the session
environment when you attach (unless you change the update-environment
option), which means its new value will be used for new panes in the
attached session. But not for existing panes, tmux has no way to change
those. If you have an existing pane with the wrong SSH_AUTH_SOCK, you
will need to fix it yourself.

You will have to work out how that matches to what you are doing
yourself because what you describe makes no sense to me.

Using a new ssh-agent every time you login but keeping a tmux server
running all the time doesn't work well because SSH_AUTH_SOCK in all
existing panes in tmux will become out of date every time you start a
new ssh-agent.

It is better to start an ssh-agent the first time you log in (before you
start tmux the first time) and then use the same one forever so
SSH_AUTH_SOCK is not constantly changing. The easiest way to do that is
to do it in your shell profile with something like:

if [ ! -f ~/.ssh.agent ]; then
ssh-agent -s >~/.ssh.agent
fi
eval `cat ~/.ssh.agent` >/dev/null
if ! kill -0 $SSH_AGENT_PID 2>/dev/null; then
ssh-agent -s >~/.ssh.agent
eval `cat ~/.ssh.agent` >/dev/null
fi
> --
> 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 view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/ffa770a1-111f-53e4-3787-dbf631c24ce8%40uni-bielefeld.de.


Jörg Kastning

unread,
May 19, 2020, 2:54:30 AM5/19/20
to Nicholas Marriott, tmux-...@googlegroups.com
Hi Nicholas,

Sorry, for my bad explenation.

I'll try to give you another example for the better understanding.

1. Login to a linux machine without running ssh-agent or tmux server
2. `$ exec ssh-agent bash`
3. `$ ssh-add <My private key>`
4. `tmux` --> ssh-agent available
5. Open new window with `c-b c` --> shoot, nerver mind.

I'm so sorry. It had to be some kind of issue in my running config.
After a fresh start everything seems to work fine.

Thanks again for this great tool!

Regards,
Joerg

Reply all
Reply to author
Forward
0 new messages