多个 SSH 配置文件

Mat*_*dge 7 ssh

我喜欢在 ssh_config 文件中指定主机/身份文件/等的功能。然而,我理想地希望有几个不同的 SSH 配置,每个配置都有自己的版本控制。有没有办法从 ssh_config 中引用另一个 ssh_config 类型文件?

像这样的东西(语法是我正在寻找的,但在手册页Load中找不到。

〜/ .ssh /配置

Load config_file_a
Load config_file_b     
Run Code Online (Sandbox Code Playgroud)

〜/.ssh/config_file_a

# Options for one host
Host serverA
    HostName serverA.myserver.com
Run Code Online (Sandbox Code Playgroud)

〜/.ssh/config_file_b

# Options for another host
Host serverB
    HostName serverB.myserver.com
Run Code Online (Sandbox Code Playgroud)

sum*_*mek 10

从2016 年OpenSSH v7.3开始,您可以使用Include按照以下方式使用man ssh_config

\n
Include\n             Include the specified configuration file(s).  Multiple\n             pathnames may be specified and each pathname may contain\n             glob(7) wildcards and, for user configurations, shell-like\n             \xe2\x80\x98~\xe2\x80\x99 references to user home directories.  Wildcards will be\n             expanded and processed in lexical order.  Files without\n             absolute paths are assumed to be in ~/.ssh if included in a\n             user configuration file or /etc/ssh if included from the\n             system configuration file.  Include directive may appear\n             inside a Match or Host block to perform conditional\n             inclusion.\n
Run Code Online (Sandbox Code Playgroud)\n


ish*_*aaq 0

据我所知,没有办法做到这一点。如果你真的需要这样做,我建议编写脚本 - 即编写一个像这样的脚本(假设是 bash 脚本,但你可以使用你的操作系统支持的任何脚本):

cat /path/to/config1 /path/to/config2 .... /path/to/configN > ~/.ssh/config
Run Code Online (Sandbox Code Playgroud)

每当您对任何一个配置文件进行更改时,请重新运行脚本。更好的是,如果您的版本控制系统支持脚本挂钩,请将其自动化。