# Is there a way for one SSH config file to include another one

opensshssh

In case it matters:

• OS: Ubuntu 10.04
• SSH: OpenSSH_5.3p1 Debian-3ubuntu5

I'd like one SSH config file to include another one. The use case would be to define whatever I want in my default .ssh/config file and then pre-pend a couple of extra things in a separate file (e.g. ~/.ssh/foo.config). I want the second file to incorporate the first one, though, so I don't have to duplicate everything in the first one. Is that doable? Thanks!

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

Include

Include the specified configuration file(s).  Multiple pathnames may be specified and each pathname may contain glob(3) wildcards and, for user configurations, shell-like “~” references to user home directories.  Files without absolute paths are assumed to be in ~/.ssh if included in a user configuration file or /etc/ssh if included from the system configuration file.  Include directive may appear inside a Match or Host block to perform conditional inclusion.
Source: ssh_config(5).

You should put the Include clause on top of the file.

For example you could have in ~/.ssh/config:

Include config.d/home

Host github.com
HostName github.com
User git


and in ~/.ssh/config.d/home:

Host laptop
HostName laptop.lan


From the comments, use the below to include all files in the config.d directory:

Include config.d/*