SSH config wildcard on expanded Hostname
You can simply set CanonicalizeHostname
to yes
to reparse ssh_config with the canonical hostname of your alias. For example:
CanonicalizeHostname yes
Host *.mydomain.com
User myusername
Host host1
HostName host1.mydomain.com
Alternatively, if you want to also remap hostnames, you can use Match
instead of Host
to match only the canonical hostnames. For example, in:
Match canonical host="*.mydomain.com"
User myusername
Host host2.mydomain.com
HostName host2.otherdomain.com
The user directive will not be set when you connect to host2.mydomain.com
.
Simply use:
Host *.mydomain.com host1
User myusername
Host host1
Hostname host1.mydomain.com
- Alternative patterns are supplied by a delimiting blank in a Host line.
- All matching Host Patterns are applied.
- If an option occurs multiple times, only the 1st occurance is used
You can use %h.mydomain.com in your .ssh/config.
Host host?
User myusername
Hostname %h.mydomain.com
Host host??
User myusername
Hostname %h.mydomain.com
Host host???
User myusername
Hostname %h.mydomain.com
Now you can do:
ssh host1instead of
ssh host1.mydomain.com
ssh host10instead of
ssh host10.mydomain.comand ssh host100
Regards, Bert