如何将一些设置应用于除另一个主机之外的 ssh 主机?

如何将一些设置应用于除另一个主机之外的 ssh 主机?

我已经为我的 进行了相对完整的设置~/.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 [email protected]
   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 [email protected]
   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。

我怎样才能做我想做的事?

答案1

之后的模式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

相关内容