My requirements are as follows
My current SSH config is a
Host shortname1?
Hostname %h.prod.xyz.com
Host test-myname
Hostname combo.test-myname.xyz.com
Host *.xyz.com
Hostname %h
Hostname *.xyz.com
User myuser
Port 12345
IdentityFile ~/.ssh/id_rsa
The exact use cases are
ssh shortname1a; ssh shortname1b; ssh test-myname; ssh combo.test-myname.xyz.com
Host *.xyz.com
was a recent addition after debugging for the last use case, and this somehow seems to break the first 2.
Is this the right way or is there a neater way?
On top of figuring out why the config was "breaking", I discovered a new directive Match
. This lets me do what I intend
Host shortname1?
Hostname %h.prod.xyz.com
Host test-myname
Hostname combo.test-myname.xyz.com
Host *.xyz.com
Hostname %h
Match Host *.xyz.com
User myuser
Port 12345
IdentityFile ~/.ssh/id_rsa
This config does exactly what I need. I needed to use Host
instead of Hostname
in the match because it didnt seem to accept Hostname
but Host
seems to be exactly what I need.
I was having arbitrary behaviour because I missunderstood that Hostname
could not be used as I was using before, as a filter or match like statement. It can only be used inside a Host
, or Match
and as such, was implicitly below the last Host
statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With