Multiple 'Host *' in ssh_config?

From the ssh_config manual:

Since the first obtained value for each parameter is used, more host-specific declarations should be given near the beginning of the file, and general defaults at the end.

So in your example, all hosts will use User harleypig and IdentityFile ~/.ssh/personal_id_rsa.

Think of Host directives with wildcards as fallbacks: use the following settings only if they haven't been set yet. You need to write something like this:

Host host1
Hostname host1.com
Host host2
Hostname host2.com
Host host*
User harleypig
IdentityFile ~/.ssh/personal_id_rsa

You can put multiple patterns on a Host line if a given set of host aliases can't be matched with wildcards, e.g. Host host* more* outlier.


You are definitely doing it wrong.

  • You should always put Host * as the last entry.
  • You can not have multiple Host * entries

If your work machines have a name format which you can generalize to target just the work machines, for e.g: machine1.work.com, host.work.com, fileserver.work.com then you can target your work machines as:

Host *.work.com
User alan.young
IdentityFile ~/.ssh/work_id_rsa

Same applies for your personal machines.

Tags:

Ssh

Openssh