23

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

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

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

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

谢谢

4

2 回答 2

25

此行将提供所需的功能:

Host 192.168.1.*
IdentityFile KeyFile

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

于 2014-02-28T08:53:16.447 回答
15

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.*

于 2012-12-10T07:58:43.383 回答