5

I have a relatively full setup for my ~/.ssh/config. This is what's at the top:

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

I want to make it such that ControlMaster etc do not apply to github; they apparently actively disconnect these persistent connections, which I understand and respect.

So to be clear:

 $ 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

So I read some docs, I asked in IRC, and this is what I ended up with:

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

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

So now github correctly does not use 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_*

But neither does anything else:

 $ 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_*

I tried making the host line Host !github.com, * and Host *, !github.com but as far as I can tell when I do that it always applies to github.

How can I do what I want?

Frew Schmidt
  • 1,221
  • 3
  • 16
  • 28

2 Answers2

12

Patterns after Host are separated with spaces, not commas, so this should work:

Host * !github.com
    ControlMaster auto
    ControlPath /tmp/ssh_mux_%h_%p_%r
    ControlPersist 24h
  • Thank you. On macOS BigSur at least, I found that (1) `Host !bitbucket.org` worked for me rather than (2) `Host * !bitbucket.org` - which meant I got "Forbidden fatal: Could not read from remote repository.". Using (1) allowed it to work - I could git pull. I'm using this in conjunction with https://superuser.com/a/1077869/21353 – therobyouknow Dec 29 '20 at 22:17
3

rudi_s on IRC helped me come up with the solution:

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
Frew Schmidt
  • 1,221
  • 3
  • 16
  • 28
  • The reason this works is because the Host entries are parsed in order, so the first matching entry is used. I'm not familiar with the ! matching pattern, so can't say for sure why it doesn't work. I suggest that it might be a feature newer than your SSH client. – Slartibartfast Mar 22 '14 at 21:21
  • While this works, the other answer is what I was trying for and ends up with a more succinct solution so I'm gonna mark it as correct. – Frew Schmidt Mar 23 '14 at 01:17