如何将某些设置应用于除其他主机之外的ssh主机?


3

我有一个相对完整的设置~/.ssh/config。这就是最重要的:

Host *
   ControlMaster auto
   ControlPath /tmp/ssh_mux_%h_%p_%r
   ControlPersist 24h
   BatchMode yes
   Ciphers blowfish-cbc
   Compression yes
   VisualHostKey yes

我想让它等ControlMaster不适用于github; 他们显然主动断开这些持久的联系,这是我理解和尊重的。

所以要明确:

 $ rm /tmp/ssh_mux_*
 $ ssh git@github.com
   PTY allocation request failed
   Hi frioux! You've successfully authenticated, but GitHub does not provide shell access.
   Shared connection to github.com closed.

 $ ls /tmp/ssh_mux_*
   /tmp/ssh_mux_github.com_22_git

所以我读了一些文档,我在IRC中问过,这就是我最终的结果:

Host !github.com
   ControlMaster auto
   ControlPath /tmp/ssh_mux_%h_%p_%r
   ControlPersist 24h

Host *
   BatchMode yes
   Ciphers blowfish-cbc
   Compression yes
   VisualHostKey yes

所以现在github正确地不使用ControlMaster:

 $ rm /tmp/ssh_mux_*
 $ ssh git@github.com
   Host key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
   +--[ RSA 2048]----+
   |        .        |
   |       + .       |
   |      . B .      |
   |     o * +       |
   |    X * S        |
   |   + O o . .     |
   |    .   E . o    |
   |       . . o     |
   |        . .      |
   +-----------------+

   PTY allocation request failed
   Hi frioux! You've successfully authenticated, but GitHub does not provide shell access.
   Shared connection to github.com closed.

 $ ls /tmp/ssh_mux_*

但其他任何事情都没有:

 $ rm /tmp/ssh_mux_*
 $ ssh cs ls
   Host key fingerprint is 89:d1:40:7f:0d:11:28:10:ce:23:e6:a9:12:9d:a1:5b
   +--[ RSA 2048]----+
   |    o+o  .+o     |
   |   o  .+.  o     |
   |  + + ..o . .    |
   | = = . o o       |
   |o E   . S        |
   | =               |
   |+                |
   |.                |
   |                 |
   +-----------------+

   /home/frew
   bin
   code
   irclogs
   lib
   out
   test

 $ ls /tmp/ssh_mux_*

我尝试制作主机线Host !github.com, *Host *, !github.com但据我所知,它总是适用于github。

我怎么能做我想做的事?

Answers:


6

后面Host的模式用空格分隔,而不是逗号,所以这应该工作:

Host * !github.com
    ControlMaster auto
    ControlPath /tmp/ssh_mux_%h_%p_%r
    ControlPersist 24h

2

IRC上的rudi_s帮我提出了解决方案:

Host github.com
   ControlMaster  no
   ControlPath    no
   ControlPersist no

Host *
   ControlMaster auto
   ControlPath /tmp/ssh_mux_%h_%p_%r
   ControlPersist 24h
   BatchMode yes
   Ciphers blowfish-cbc
   Compression yes
   VisualHostKey yes

这样做的原因是因为Host <match>条目按顺序解析,因此使用第一个匹配条目。我不熟悉!<hostname>匹配模式,所以不能确定为什么它不起作用。我建议它可能是比SSH客户端更新的功能。
Slartibartfast 2014年

虽然这是有效的,但另一个答案是我正在尝试的并最终得到一个更简洁的解决方案,所以我要将其标记为正确。
Frew Schmidt 2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.