ssh config wildcards

I just wanted to make sure no one forgets that wildcards can be used in your .ssh/config. This can be extremely helpful. For example say you have 100 nodes that have a simple nameing scheme of nodexxxx. You can add the following into your ssh config and pre-poplulate settings.

Host node*
    User staffuser
    IdentityFile ~/.ssh/staff_key

That would cause any ssh connection matching node* to use the user staffuser and .ssh/staff_key as the ssh key. By the same token you could do this.

Host *.locallan.domin.com
    User me

This could be useful if you have networks of machines that hook into different authentication systems. Nothing groundbreaking by any means but its useful so dont forget about it.

6 Comments

  • Nevermind. I am apparently blind :-)

  • I meant to prepend a stupid question to my previous comment, just so you know. :-)

    Great post. I didn’t know about this ability, but it’s really excellent (and handy).

  • Anonymous Linux Unknow wrote:

    Is there a way to do something like this?:

    Host asdf*
    HostName asdf*.example.com

  • @Anonymous not that I know of. asdf*.example.com would be multiple hosts. You can do
    Host asdf*.example.com
    User staffuser
    IdentityFile ~/.ssh/staff_key

    So that those settings apply to anythign that matches asdf*.example.com but the HostName directive tells you what hostname to apply to that alias. But I think the above example does what you want.

  • Mark Hartog Mac OS X Firefox 15.0.1 wrote:

    Host *.corp.domain.com
    User me

    The above syntax fails on OS X Lion. Wish I knew why.

  • Re: Host asdf*

    What you want in your ~/.ssh/config is something like:

    Host asfd*
    User me
    HostName %h.corp.domaindom

Leave a Reply

Your email is never shared.Required fields are marked *

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha