I followed the git guide but I have this strange issue when trying to connect to github:
$ ssh -v [email protected]
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /c/Documents and Settings/mugues/.ssh/config
debug1: Applying options for github.com
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: connect to address 207.97.227.239 port 22: Attempt to connect timed out without establishing a connection
ssh: connect to host github.com port 22: Bad file number
This is my config file under .ssh
Host github.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile "C:\Documents and Settings\mugues\.ssh\id_rsa"
TCPKeepAlive yes
IdentitiesOnly yes
Any idea?
If SSH is blocked over 22
just update your origin
to https
git remote set-url origin https://github.com/ACCOUNT_NAME/REPO_NAME.git
verify that changes were made
git remote -v
This worked for me:
ssh -v [email protected] -p 443
In my case simply restarting the WiFi router helped.
This is the simple solution for saving some typing you can use the following steps in git bash easily..
(1) create the remote repository
git remote add origin https://{your_username}:{your_password}@github.com/{your_username}/repo.git
Note: If your password contains '@' sign use '%40' instead of that
(2) Then do anything you want with the remote repository
ex:- git push origin master
Try to quit the git bash instance through which you made the setup and try reopening. It eventually worked for me.
I saw this issue when I access bitbucket in corporate network, while git works fine in home network.
$ git pull
ssh: connect to host bitbucket.org port 22: Bad file number
fatal: Could not read from remote repository.
I used https protocol to workaround this.
$ git pull https://[email protected]/myaccount/myrepo.git
Password for 'https://[email protected]':
Please use corresponding words to replace "myaccount" and "myrepo".
Creating the config file to use port 443 didn't work for me. Finally I tried to turn off my wifi connection, turn it on again and the problem disappeared. Weird. Silly solution but it may help someone :)
Maybe your firewall or a blocker application (PeerBlock etc.) is blocking your port
Double check that you have published your public keys through your GitHub Administration interface.
Then make sure port 22 isn't somehow blocked (as illustrated in this question)
What I found is that, this happens when your connection is poor. I had it a few minutes ago when pushing to my repo, it kept failing and a while after that, the connection went down.
After it came back up, the push immediately went through.
I believe it can be caused by either a drop in connection from either your side or theirs.
In my case the IP address of our git host had changed.
Simply flushing the DNS cache fixed the problem.
On windows I tried to do quit git bash and re-run but didn't work, finally me(frustated) did a restart and it worked the next time :)
The key information is written in @Sam's answer but not really salient, so let's make it clear.
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
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.
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.
The following solution worked for me when tried to SSH into to AWS EC2 Ubuntu instance from my Windows 7 (32 Bit) PC behind corporate firewall setting up Proxy-
Add the following block to C:\Users\<YOUR_WINDOWS_USER>\.ssh\config
file-
> Host *
> ProxyCommand "C:/Program Files/Git/mingw32/bin/connect.exe" -H <YOUR_PROXY_SERVER_HOST>:<YOUR_PROXY_SERVER_PORT> %h %p
> IdentityFile "<PATH_OF_YOUR_IDENTITY_FILE>"
> TCPKeepAlive yes
> IdentitiesOnly yes
>
> Host <SERVER_HOST_NAME_OR_IP_YOU_WANT_TO_SSH_INTO>
> Port <SERVER_HOST_PORT_YOU_WANT_TO_SSH_INTO>
> Hostname <SERVER_HOST_NAME_OR_IP_YOU_WANT_TO_SSH_INTO>
You will need to add similar configuration per host that you want to SSH into.
Check your remote with git remote -v Something like ssh:///gituser@myhost:/git/dev.git
is wrong because of the triple /// slash
You can also try to:
telnet example.com 22
to see if you have connectivity to the server. I saw this message and it ended up being the VPN I was on was blocking access. Disconnected from the VPN and I was good to go.
I had the problem when I had an open FileZilla-Connection on Windows. Closed FileZilla -> Problem solved.
I just had the same problem and tried every solution that I could find, but none worked. Eventually, I tried quitting Git Bash and re-opening it, and everything worked perfectly.
So, try quitting Git Bash and re-opening it.
Source: Stackoverflow.com