Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple SSH config files

Tags:

ssh

I like the ability to specify hosts/identity files/etc in the ssh_config file. However, I would ideally like to have a couple different SSH configurations each under their own version control. Is there any way to reference another ssh_config type file from within ssh_config?

Something like this (the Load syntax is what I am looking for but can't find in the man pages.

~/.ssh/config

Load config_file_a
Load config_file_b     

~/.ssh/config_file_a

# Options for one host
Host serverA
    HostName serverA.myserver.com

~/.ssh/config_file_b

# Options for another host
Host serverB
    HostName serverB.myserver.com
like image 567
Matt Dodge Avatar asked Jul 21 '26 06:07

Matt Dodge


1 Answers

Since OpenSSH v7.3 in 2016, you can use Include as per man ssh_config:

Include

Include the specified configuration file(s). Multiple pathnames may be specified and each pathname may contain glob(7) wildcards and, for user configurations, shell-like ‘~’ references to user home directories. Wildcards will be expanded and processed in lexical order. 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.

So to include ~/.ssh/config_file_a and ~/.ssh/config_file_b you would write the following in ~/.ssh/config:

Include config_file_a
Include config_file_b

Note that it is possible to Include a directory:

# includes config.d/file_a and config.d/file_b for example
Include config.d/*
like image 149
sumek Avatar answered Jul 23 '26 18:07

sumek