I ran across the following in Gentoo Linux's wiki about dynamic jumphost list:
ProxyCommand ssh $(echo %h | sed 's/+[^+]*$//;s/\([^+%%]*\)%%\([^+]*\)$/\2 -l \1/;s/:/ -p /') nc -w1 $(echo %h | sed 's/^.*+//;/:/!s/$/ %p/;s/:/ /')
It works, but I would like to understand the sed
expression completely.
Reading its original reference, I was able to get a good understanding of the recursive invocation of the command, using the Host *+*
pattern. But I have two questions:
- The expression uses
%%
. To see why, I usedssh -v
, and observed that when thessh
client parses the$HOME/.ssh/config
, it seemed that the first%
is stripped. Attempting to confirm the above, I downloaded the openssh source codes, but thereadconf.c
didn't give me a clue. I am new to OpenSSH source codes, but am not afraid to compile it with debug info, andgdb
it. Nevertheless, if there is a quicker way to confirm my conjecture, I would appreciate a hint. The
ssh -v
also revealed that:[...] debug1: Executing proxy command: exec ssh $(echo zackp%node0+zackp%node1+node3 | sed 's/+[^+]*$//;s/\\([^+%]*\\)%\\([^+]*\\)$/\\2 -l \\1/;s/:/ -p /') [....]
i.e. the
\(
is now escaped with a\
in the subshell. Why this is necessary?
Thanks,
--Zack