Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to have a wildcard in my SSH config to set my default username to a particular value for all hosts on a certain domain. But I also want to have some short names for some particular hosts. I expected something like this to work:

Host *.mydomain.com
    User myusername
Host host1
    Hostname host1.mydomain.com

With those settings, if I type ssh host1.mydomain.com it evaluates to myusername@host1.mydomain.com, but if I type ssh host1 it doesn't apply my User setting and I instead see mylocalusername@host1.mydomain.com.

Is there a way to have the wildcards match on the final expanded hostname so I can type the short or long form and get the same results?

share|improve this question
    
What if you switch the order, putting the wildcard section second. –  esmit Feb 27 at 22:45
    
Have you tried it? I'm pretty sure that just gets you the right username with the domain wrong, if anything. –  Mu Mind Feb 28 at 3:06
    
I haven't tried it, that's why I made it a comment answer as something to try, instead of a downvotable answer. –  esmit Mar 1 at 6:28

1 Answer 1

up vote 7 down vote accepted

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
share|improve this answer
1  
That saves a little typing at least. Sounds like you're not aware of any way to avoid duplicating the domain information? –  Mu Mind Sep 3 '12 at 15:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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