This question already has an answer here:

I can alias individual hosts in .ssh/config like this:

Host nickname
    Hostname host1.example.com

But sometimes I want to alias a whole domain, so as to save typing on the command line for machines on that domain:

Host *.nick
    Hostname %h.really.long.domain.example.com

That doesn't work as written, of course. Is there something that would?

Comments have suggested this question as a duplicate, but that solution doesn't work for this use case; it requires all hosts to be explicitly listed in the config file. I'm looking for a global method; I want to tell SSH 'rewrite any host of the form host???.short as host???.really.long.example.com.'

Think of it like an equivalent of sed s/.short/.really.long.etc/

marked as duplicate by thrig, Timothy Martin, Jesse_b, G-Man, Archemar Apr 6 '18 at 13:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


There's no way to perform a replacement in that manner, but it is possible to use CanonicalDomains to append domains to a hostname before attempting to check if they exist.

CanonicalDomains really.long.domain.example.com
CanonicalizeHostname yes

Host *.really.long.domain.example.com
  • Hrm. Wouldn't the block above have the same practical effect as Host *? – Andrew Apr 5 '18 at 20:59
  • A bit disappointing that it can't be done as desired, but oh well, a negative answer is still an answer. – Andrew Apr 5 '18 at 21:00
  • @Andrew: No, because Host * affects all arbitrary hosts whereas this only affects hosts that can be resolved to that FQDN. – Ignacio Vazquez-Abrams Apr 5 '18 at 22:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.