Linux – Configuring SSH for Different DNS Domains

linuxssh

I have two platforms with many servers I want to connect to via ssh.

I have in resolv.conf

search domain1.net domain2.org

So I only have the machine name to type for ssh.

I want to have an ssh config per domain:

  • user admin for every machine of domain1.net
  • user root for every machine of domain2.org

How can I achieve that ?

Host, Hostname directives seems to only works with what you type in the ssh command, not what is expanded with DNS suffixes

Best Answer

I believe OpenSSH CAN do canonicalization. Please have a look at the following options in ssh_config man page:

  • CanonicalizeHostname
  • CanonicalizeFallbackLocal
  • CanonicalizeMaxDots
  • CanonicalizePermittedCNAMEs
  • Host
  • Match with canonical option

Please note, this may require newer OpenSSH version than the one you have (I have 7.4p1).