【问题标题】:ssh-config by host subnet按主机子网的 ssh-config
【发布时间】:2019-09-27 00:57:33
【问题描述】:

所以我的 10.10.10.x 子网中有一大堆机器,它们基本上都以相同的方式配置。我将它们与我的 10.10.11.x 子网中用于不同目的的机器区分开来。

我希望能够输入“ssh 10.x”连接到 10. 网络上的机器,输入“ssh 11.x”连接到 11 网络上的机器。

我知道我可以在我的 ~/.ssh/config 中设置单个机器以允许访问完整的 ip,或者像这样的速记版本:

Host 10.10.10.11 10.11
HostName 10.10.10.11
User root

对于我网络上的许多主机来说,这可能会变得非常重复,所以我的问题是,有没有办法将其指定为整个子网的模式,例如:

Host 10.10.10.x
User root

Host 10.x
HostName 10.10.10.x
User root

谢谢

【问题讨论】:

    标签: ssh


    【解决方案1】:

    这一行将提供所需的功能:

    Host 192.168.1.*
    IdentityFile KeyFile
    

    如果您尝试连接 ip 在此子网中的服务器,您将能够建立 ssh 连接。

    【讨论】:

    • 这基本上可以按我的意愿工作,但是有没有办法可以访问 '*' 部分,例如我上面的用例希望通过模式将某个范围映射到主机名?跨度>
    • 我必须使用“主机 192.168.1.?”而是在 OS X 中
    • 我可以在连接到 IP 时使用此功能,但在连接到该子网中的主机名时无法使用。这应该在使用主机名连接时起作用吗?
    • 如果子网中的主机通过其主机名访问则不起作用
    【解决方案2】:

    来自ssh_config(5) 联机帮助页:

     A pattern consists of zero or more non-whitespace characters, ‘*’ (a
     wildcard that matches zero or more characters), or ‘?’ (a wildcard that
     matches exactly one character).  For example, to specify a set of decla‐
     rations for any host in the “.co.uk” set of domains, the following pat‐
     tern could be used:
    
           Host *.co.uk
    
     The following pattern would match any host in the 192.168.0.[0-9] network
     range:
    
           Host 192.168.0.?
    
     A pattern-list is a comma-separated list of patterns.  Patterns within
     pattern-lists may be negated by preceding them with an exclamation mark
     (‘!’).  For example, to allow a key to be used from anywhere within an
     organisation except from the “dialup” pool, the following entry (in
     authorized_keys) could be used:
    
           from="!*.dialup.example.com,*.example.com"
    

    所以你可以使用host 10.*

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-05
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多