I am trying to set up my .ssh/config
so that it only uses ProxyCommand
when it can't reach the server locally. However, I'm struggling to make the Match
keyword match multiple hosts, so I have a rather long config file.
For example. I have
Match host="X" !exec "is_reachable X"
User me
ProxyCommand ssh me2@proxy exec netcat %h %p 2> /dev/null
ForwardAgent yes
Match host="Y" !exec "is_reachable Y"
User me
ProxyCommand ssh me2@proxy exec netcat %h %p 2> /dev/null
ForwardAgent yes
...
X
and Y
are on the same network so if one of them is reachable, so is the other one. I don't really need the argument of is_reachable
to be changed. Ideally, I'd like to have something like:
Match host="X Y" !exec "is_reachable X"
User me
ProxyCommand ssh me2@proxy exec netcat %h %p 2> /dev/null
ForwardAgent yes
That matches both X
and Y
. I have around 15 hostnames and I don't want to have a separate rule for all of them.
I have seen solutions like Only apply Match keyword to single Host in ssh config but they only deal with a single host.