Linux – Can you have more than one ~/.ssh/config file

bashlinuxsshunix

We have a bastion server that we use to connect to multiple hosts, and our .ssh/config has grown to over a thousand lines (we have hundreds of hosts that we connect to). This is beginning to get a little unwieldy and I'd like to know if there is a way to break the .ssh/config file up into multiple files. Ideally, we'd specify somewhere that other files would be treated as an .ssh/config file, possibly like:

~/.ssh/config
  ~/.ssh/config_1
  ~/.ssh/config_2
  ~/.ssh/config_3
  ...

I have read the documentation on ssh/config, and I don't see that this is possible. But maybe someone else has had a similar issue and has found a solution.

Best Answer

The ~/.ssh/config file don't have a directive for including other files, possibly related to SSH's check for file permissions.

Suggestions around this can include a script to cat several changes together either on the system or via checkin hooks on a repository. One might also look into tools such as Puppet or Augeas.

However you approach it, though, you'll have to concatenate individual files to be a single file from outside of the file.

$ cat ~/.ssh/config_* >> ~/.ssh/config

note: overwrite: > v.s. append: >>

Update December 2017:

From 7.3p1 and up, there is the Include option. Which allows you to include configuration files.

Include
    Include the specified configuration file(s).  Mul‐
    tiple pathnames may be specified and each pathname
    may contain glob(3) wildcards and, for user config‐
    urations, shell-like “~” references to user home
    directories.  Files without absolute paths are
    assumed to be in ~/.ssh if included in a user con‐
    figuration file or /etc/ssh if included from the
    system configuration file.  Include directive may
    appear inside a Match or Host block to perform con‐
    ditional inclusion.