2012-07-17 41 views
14

所以我在10.10.10.x子網上有一大堆機器,它們基本上都是用相同的方式配置的。我將這些與我的10.10.11.x子網中的機器區分開來,這個子網用於不同的目的。主機子網的ssh-config

我希望能夠鍵入'ssh 10.x'連接到10.網絡和'ssh 11.x'上的機器以連接到11網絡上的機器。

我知道我可以設置單獨的機器允許訪問完整的IP,或者簡寫像這樣在我的〜/ .ssh /配置:

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 

感謝

回答

14

這條線將提供所需功能:

Host 192.168.1.* 
IdentityFile KeyFile 

如果你試圖連接的服務器的IP是該子網中,您將能夠建立SSH連接。

+0

這基本上是我想要的工作方式,但有沒有辦法可以訪問'*'部分,例如我上面想要根據模式將特定範圍映射到HostName的用例? – jdeuce 2014-09-25 20:26:54

+0

我不得不使用'Host 192.168.1。?'而不是在OS X中 – 2016-06-28 03:38:08

12

的手冊頁:

圖案由零個或多個非空白字符,「*」(一個 通配符匹配零個或多個字符),或「?」(一個通配符即 匹配一個字符)。例如,要指定一組decla- 口糧在「.co.uk」組域的任何主機,下面PAT- 燕鷗可用於:

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