gpakosz/.tmux

Hostname not displaying when already using ProxyCommand

Hellspam opened this issue ยท 24 comments

Hi,

I'm trying to get the hostname to display when using ssh.
We use https://github.com/gravitational/teleport at our company, and define this in our ssh config file:

ProxyCommand /usr/local/bin/tsh proxy ssh --cluster=<host> --proxy=<host> %r@%h:%p

When I ssh to a server, I don't get the hostname displayed in the bottom right:
image

But when I use tsh ssh to login to the service, it works fine:
image

I'd guess it has something to do with the ProxyCommand usage in _hostname.

Hello @Hellspam ๐Ÿ‘‹

Can you please help me investigate what's happening by do the following with only 2 panes?

Let's name them pane 1 and pane 2

  • In pane 2:
    • Run $ tmux display -p '#{pane_tty}' โ†’ This will display a value like /dev/ttysYYY
    • Then ssh to a remote host
  • In pane 1:
    • Run ps -t /dev/ttysYYY -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
    • And paste the result here

Pane 1:

tmux display -p '#{pane_tty}'
/dev/ttys016
ssh bitbucket00101
[roy.a@bitbucket00101 ~]$

Pane 2:

 ps -t /dev/ttys016 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
roy.a                           84276 37599 -zsh
roy.a                           93868 84276 ssh bitbucket00101
roy.a                           93877 93868 /usr/local/bin/tsh proxy ssh --cluster=teleport.XXXXXXX.com

Did you truncate the output a bit too much? There's no sign of --proxy=<host> %r@%h:%p

What's tsh btw?

Hi,
You're right sorry, I'm new to tmux I didn't know it truncated lines ๐Ÿ˜„

I ran the test again both using tsh and using ssh.
tsh is https://github.com/gravitational/teleport which is what our company uses for SSO for ssh basically.
I can ssh to hosts with either:

  • tsh ssh <host> - opens login to SSO once every 8 hours, after login, ssh to host via tsh
  • ssh <host> - requires modifying our ssh config files with configuration for teleport - there are other configurations there but I am guessing the relevant one in this case is the ProxyCommand.

When running tsh ssh <host>:

Pane 1:
 tmux display -p '#{pane_tty}'
/dev/ttys006
tsh ssh <host>

Pane 2:
ps -t /dev/ttys006 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
roy.a                           45230 37599 -zsh
roy.a                           58516 45230 tsh ssh <host>

This is the one that displays the user/hostname in the status line.

When running ssh <host>:

Pane 1:
 tmux display -p '#{pane_tty}'
/dev/ttys006 
ssh <host>

Pane 2:
ps -t /dev/ttys006 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
roy.a                           45230 37599 -zsh
roy.a                           94803 45230 ssh <host>
roy.a                           94816 94803 /usr/local/bin/tsh proxy ssh --cluster=<TELEPORT_HOST> --proxy=<TELEPORT_HOST> roy.a@<HOST>:3022

Sorry for closing and reopening, my bad.

What does the following do

$ ssh -G bitbucket00101 | head -4

Redact as necessary.

ssh -G bitbucket00101.XXXXX | head -4
user roy.a
hostname bitbucket00101.XXXXX
port 3022
addressfamily any

Can you please try the gh-690 branch?

Hi,
Just tried your branch, no change.

Can you please help me investigate what's happening by do the following with only 2 panes?

Let's name them pane 1 and pane 2

  • In pane 2:
    • Run $ tmux display -p '#{pane_pid} #{pane_tty}' โ†’ This will display a value like XXXX /dev/ttysYYY
    • Then ssh to a remote host
  • In pane 1:
    • Run ps -t /dev/ttysYYY -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
    • And paste the result here
  • In pane 1:
    • Run cut -c3- ~/.tmux.conf | sh -sx _pane_info XXXX /dev/ttysYYY
    • And paste the result here

Pane 2:

tmux display -p '#{pane_pid} #{pane_tty}'
95252 /dev/ttys004
ssh bitbucket00101
[roy.a@bitbucket00101 ~]$

Pane 1:

ps -t /dev/ttys004 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
roy.a                            6387 95252 ssh bitbucket00101
roy.a                            6396  6387 /usr/local/bin/tsh proxy ssh --cluster=<TELEPORT_HOST> -proxy=<TELEPORT_HOST> roy.a@bitbucket00101:3022
roy.a                           95252 37599 -zsh

cut -c3- ~/.config/tmux/tmux.conf | sh -sx _pane_info XXXX /dev/ttys004
+ :
+ set -e
+ unset GREP_OPTIONS
+ export LC_NUMERIC=C
+ LC_NUMERIC=C
+ set +H
+ set +H
+ printf ''
+ sed -E s///
++ uname -s
+ _uname_s=Darwin
+ '[' -z /private/tmp/tmux-651909402/default,37599,0 ']'
+ '[' -z /private/tmp/tmux-651909402/default ']'
+ '[' -z /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux ']'
+ '[' /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux = tmux ']'
++ tmux -V
++ /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux -S /private/tmp/tmux-651909402/default -V
++ awk '{gsub(/[^0-9.]/, "", $2); print ($2+0) * 100}'
+ _tmux_version=330
+ command -v pkill
+ _pane_info XXXX /dev/ttys004
+ pane_pid=XXXX
+ pane_tty=ttys004
+ case "$_uname_s" in
+ ps -t /dev/ttys004 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
+ awk -v pane_pid=XXXX '
        ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ {
          user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
        }
        END {
          pid = pane_pid
          while (child[pid])
            pid = child[pid]

          print pid":"user[pid]":"command[pid]
        }
      '

You don't have the changes from thegh-690 branch ๐Ÿ™‚

I just checked my tmux.conf for the changes, they seem to appear fine:

cat ~/.config/tmux/tmux.conf| grep "tsh"
#         ((/ssh/ && !/-W/ && !/tsh proxy ssh/) || !/ssh/) && !/tee/ && $5 == tty {

I ran reload in tmux and also tried opening a new session - anything I'm missing?

Well in the result of cut -c3- ~/.config/tmux/tmux.conf | sh -sx _pane_info XXXX /dev/ttys004 you pasted above,
the changes are not visible

...
+ awk -v pane_pid=XXXX '
        ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ {
...

Woops!

Pushed a fixup commit

Still no luck, verified the cut command you sent contains the tsh command now -

cut -c3- ~/.config/tmux/tmux.conf | sh -sx _pane_info XXXX /dev/ttys004
+ :
+ set -e
+ unset GREP_OPTIONS
+ export LC_NUMERIC=C
+ LC_NUMERIC=C
+ set +H
+ set +H
+ printf ''
+ sed -E s///
++ uname -s
+ _uname_s=Darwin
+ '[' -z /private/tmp/tmux-651909402/default,37599,0 ']'
+ '[' -z /private/tmp/tmux-651909402/default ']'
+ '[' -z /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux ']'
+ '[' /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux = tmux ']'
++ tmux -V
++ /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux -S /private/tmp/tmux-651909402/default -V
++ awk '{gsub(/[^0-9.]/, "", $2); print ($2+0) * 100}'
+ _tmux_version=330
+ command -v pkill
+ _pane_info XXXX /dev/ttys004
+ pane_pid=XXXX
+ pane_tty=ttys004
+ case "$_uname_s" in
+ ps -t /dev/ttys004 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
+ awk -v pane_pid=XXXX '
        ((/ssh/ && !/-W/ && !/tsh ssh proxy/) || !/ssh/) && !/tee/ {
          user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
        }
        END {
          pid = pane_pid
          while (child[pid])
            pid = child[pid]

          print pid":"user[pid]":"command[pid]
        }
      '
XXXX::

Wait did you replace XXXX with the #{pane_pid} value when trying the command?

Do you mean in this command?

cut -c3- ~/.config/tmux/tmux.conf | sh -sx _pane_info XXXX /dev/ttys004

Oh sorry I see the issue now.
Fixed command here:

cut -c3- ~/.config/tmux/tmux.conf | sh -sx _pane_info 96669 /dev/ttys014
+ :
+ set -e
+ unset GREP_OPTIONS
+ export LC_NUMERIC=C
+ LC_NUMERIC=C
+ set +H
+ set +H
+ printf ''
+ sed -E s///
++ uname -s
+ _uname_s=Darwin
+ '[' -z /private/tmp/tmux-651909402/default,37599,0 ']'
+ '[' -z /private/tmp/tmux-651909402/default ']'
+ '[' -z /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux ']'
+ '[' /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux = tmux ']'
++ tmux -V
++ /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux -S /private/tmp/tmux-651909402/default -V
++ awk '{gsub(/[^0-9.]/, "", $2); print ($2+0) * 100}'
+ _tmux_version=330
+ command -v pkill
+ _pane_info 96669 /dev/ttys014
+ pane_pid=96669
+ pane_tty=ttys014
+ case "$_uname_s" in
+ ps -t /dev/ttys014 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
+ awk -v pane_pid=96669 '
        ((/ssh/ && !/-W/ && !/tsh ssh proxy/) || !/ssh/) && !/tee/ {
          user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
        }
        END {
          pid = pane_pid
          while (child[pid])
            pid = child[pid]

          print pid":"user[pid]":"command[pid]
        }
      '
2694:roy.a:/usr/local/bin/tsh proxy ssh --cluster=<TELPORT_HOST> --proxy=<TELEPORT_HOST> roy.a@bitbucket00101:3022

I fixed the issue, seems we need to use tsh proxy ssh instead of tsh ssh proxy.
#693

Oh right,

I'll keep my own branch to merge though. Feel free to give gh-690 a try one last time

Works fine, thanks for the assistance.