Grouping hosts in SSH Config

10

Can I configure the hosts in my SSH config by groups? For example, I'd like to set a single same user to be used for one group of hosts and another one for another group of hosts.

If it's not possible out of the box, I guess there might be tools that can write or manage your ssh_config through a config file format with some richer options?

Jorn van de Beek

Posted 2011-10-21T09:54:30.623

Reputation: 103

Answers

15

You should take a look at man 5 ssh_config for all the details on this, but yes, you can do that by doing this in your ~/ssh_config:

Host srv1 srv2 srv3
    User jorn

Host srv4 srv5 srv6
    User jornv

Host *.company.com
    User jornw

The * can also be used to do string matching for hosts

ThatGraemeGuy

Posted 2011-10-21T09:54:30.623

Reputation: 3 088

5Also you can use patterns, like *.company.com. This might be shorter if you have a lot of similar servers around. – Dave Vogt – 2012-04-25T13:50:32.157

0

You could use a template system like Jinja2 to generate ssh ~/.ssh/config. I use such system to merge multiple ssh configs from multiple envs.

neutrinus

Posted 2011-10-21T09:54:30.623

Reputation: 139

2An example of how this is achieved would be helpful. – Tim Radcliffe – 2013-05-23T09:39:57.847