gpakosz / .tmux

🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
MIT License
21.73k stars 3.34k forks source link

Hostname not displaying when already using ProxyCommand #690

Closed Hellspam closed 8 months ago

Hellspam commented 8 months ago

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.

gpakosz commented 8 months ago

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

Hellspam commented 8 months ago

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
gpakosz commented 8 months ago

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

gpakosz commented 8 months ago

What's tsh btw?

Hellspam commented 8 months ago

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:

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.

gpakosz commented 8 months ago

What does the following do

$ ssh -G bitbucket00101 | head -4

Redact as necessary.

Hellspam commented 8 months ago
ssh -G bitbucket00101.XXXXX | head -4
user roy.a
hostname bitbucket00101.XXXXX
port 3022
addressfamily any
gpakosz commented 8 months ago

Can you please try the gh-690 branch?

Hellspam commented 8 months ago

Hi, Just tried your branch, no change.

gpakosz commented 8 months ago

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

Hellspam commented 8 months ago

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]
        }
      '
gpakosz commented 8 months ago

You don't have the changes from thegh-690 branch 🙂

Hellspam commented 8 months ago

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?

gpakosz commented 8 months ago

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/ {
...
Hellspam commented 8 months ago

Maybe it the tsh command should not have been under CYGWIN case?https://github.com/gpakosz/.tmux/blob/97503a7b0b256d55e24bb09dbb9e8effaa85b25c/.tmux.conf#L528C1-L528C1

gpakosz commented 8 months ago

Woops!

gpakosz commented 8 months ago

Pushed a fixup commit

Hellspam commented 8 months ago

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::
gpakosz commented 8 months ago

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

Hellspam commented 8 months ago

Do you mean in this command?

cut -c3- ~/.config/tmux/tmux.conf | sh -sx _pane_info XXXX /dev/ttys004
Hellspam commented 8 months ago

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
Hellspam commented 8 months ago

I fixed the issue, seems we need to use tsh proxy ssh instead of tsh ssh proxy. https://github.com/gpakosz/.tmux/pull/693

gpakosz commented 8 months ago

Oh right,

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

Hellspam commented 8 months ago

Works fine, thanks for the assistance.