The key information is written in @Sam's answer but not really salient, so let's make it clear.
"Bad file number" is not informative, it's only a sign of running git's ssh on Windows.
The line which appears even without -v
switch:
ssh: connect to host (some host or IP address) port 22: Bad file number
is actually irrelevant.
If you focus on it you'll waste your time as it is not a hint about what the actual problem is, just an effect of running git's ssh on Windows. It's not even a sign that the git or ssh install or configuration is wrong. Really, ignore it.
The very same command on Linux produced instead this message for me, which gave an actual hint about the problem:
ssh: connect to host (some host or IP address) port 22: Connection timed out
Actual solution: ignore "bad file number" and get more information
Focus on lines being added with -v
on command line. In my case it was:
debug1: connect to address (some host or IP address) port 22: Attempt to connect timed out without establishing a connection
My problem was a typo in the IP address, but yours may be different.
Is this question about "bad file number", or about the many reasons why a connection could time out ?
If someone can prove that "bad file number" only appears when the actual reason is "connection time out" then it makes some sense to address why connection could time out.
Until that, "bad file number" is only a generic error message and this question is fully answered by saying "ignore it and look for other error messages".
EDIT: Qwertie mentioned that the error message is indeed generic, as it can happen on "Connection refused" also. This confirms the analysis.
Please don't clutter this question with general hints and answer, they have nothing to do with the actual topic (and title) of this question which is "Git SSH error: “Connect to host: Bad file number”". If using -v
you have more informative message that deserve their own question, then open another question, then you can make a link to it.