Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I frequently ssh into openstack instances. All of the instances are on a dedicated vlan and subnet (10.2.x.x). All of the instances have the same username (bob)

I connect like so:

ssh bob@10.2.x.x

or sometimes like this

ssh 10.2.x.x -l bob

Is it possible to configure my laptop to automatically use the name bob when I ssh into any vm on the 10.2.x.x subnet? I don't want to automatically use bob when sshing into a machine on any other subnet.

It looks like ssh config doesn't support wildcards. (Correct me if I am wrong). I'm thinking maybe an alias could do this, but I'm not sure what the syntax would be.

share|improve this question
up vote 12 down vote accepted

The ssh_config man page has a section PATTERNS which details how you can do that, you can use wildcards of * and ?. In my ~/.ssh/config:

Host 172.16.*.*
   User drav

and then on issuing ssh -vvv

debug1: Reading configuration data /home/drav/.ssh/config
debug1: /home/drav/.ssh/config line 4: Applying options for 172.16.*.*
debug1: /home/drav/.ssh/config line 46: Applying options for *

Note that these matches are canonical, so if "fred.mynetwork.com" in DNS is, issuing ssh fred.mynetwork.com will not match the Host 172.16.*.* entry. You could always however, add an additonal Host *.mynetwork.com entry to apply the same options when a DNS name is used instead.

share|improve this answer
Yes, an entry Host 10.2* will do the trick – Bananguin Aug 26 '13 at 17:18
I found 10.2.*.* caused my key to be rejected. Changing to 10.2.* caused the connection to succeed. – spuder Aug 26 '13 at 19:05
Strange, for me the x.x.*.* works :/ At least there is your comment if people find issues! – Drav Sloan Aug 26 '13 at 19:34

Your Answer


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.