3

This thread: In your ssh config is it possible to have one host entry for multiple machines on the same domain explained the 'aliases' part of my question, I was wondering if it's possible to set default username AS well as use domain aliases, so I can simply have to write something like:

ssh subdomain

I have the following in my /etc/resolv.conf file:

search my_cool_domain.com

and the following in my ssh_config file:

Host *.my_cool_domain.com
    User deploy

So I figured the following will work:

ssh subdomain

will try to connect to subdomain.my_cool_domain.com with user deploy but this does not work for some reason.

Although the following:

ssh deploy@subdomain does work, as well as: ssh subdomain.my_cool_domain.com

Any idea how can I fix this (If it's even possible) in an elegant way?

5

The patterns after the keyword "Host" are not resolved in anyway to real host names, so you cannot detect that a subdomain that your dns lookup is configured for it actually a subdomain of your main domain.

From the ssh_config manpage -

         ... The host is the hostname argument given on the command line (i.e. the
         name is not converted to a canonicalized host name before match-
         ing).

Your alternative is to, either

  1. Use "Host *" and set the default username for all hosts.
  2. When/if you have some kinds of prefixes to your subdomains, use "Host pfx1* pfx2*".
  3. Configure your shell completion and always use full host names, "Host *.mydomain" and "ssh subdomain" that completes it to "ssh subdomain.mydomain".
  4. Shell aliases and function can also be used to add the ".mydomain" part automagically. For example, "ssh-alias subdomain" that is an alias for "ssh subdomain.mydomain".
|improve this answer|||||
2

just use a combined solution with properly setup ssh_config + resolv.conf:

1 . setup /etc/resolv.conf

search my_cool_domain.com

2 . setup your ssh_config for mapping between hosts and users

Host subdomain1
    User deploy1

Host subdomain2
    User deploy2

this way ssh subdomain1 will use the required user deploy1 and the host will be qualified to it's full name by resolv.conf

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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