ssh: connect to host github.com port 22: Connection timed out

I am under a proxy and I am pushing in to git successfully for quite a while. Now I am not able to push into git all of a sudden. I have set the RSA key and the proxy and double checked them, with no avail and git is throwing me the error shown in the title of the page.

Answers


The reason could be the firewall modification as you are under a network.(In which case they may deliberately block some ports) To double check if this is the reason ... do

ssh -T git@github.com

this should timeout. If that's the case use http protocol instead of ssh this way just change your url in the config file to http. Here is how :-

git config --local -e

change entry of

 url = git@github.com:username/repo.git

to

url = https://github.com/username/repo.git

For my case none of the suggested solutions worked so I tried to fix it myself and I got it resolved.

For me I am getting this error on my AWS EC2 UBUNTU instance, what I did to resolve it was to edit the git config (or add it if it does not exist).

sudo nano ~/.ssh/config

And I added the following

Host github.com
 Hostname ssh.github.com
 Port 443

Then, run the command ssh -T git@github.com to confirm if the issue is fixed.

According to this

Sometimes, firewalls refuse to allow SSH connections entirely. If using HTTPS cloning with credential caching is not an option, you can attempt to clone using an SSH connection made over the HTTPS port. Most firewall rules should allow this, but proxy servers may interfere

Hopefully this helps anyone else who's having the same issue I did.


Basic URL Rewriting

Git provides a way to rewrite URLs using git config. Simply issue the following command:

git config --global url."https://".insteadOf git://

Now, as if by magic, all git commands will perform a substitution of git:// to https://

source: git:// protocol blocked by company, how can I get around that?


inside the .ssh folder Create "config" file

Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

Execute:

nc -v -z <git-repository> <port>

Your output should look like:

"Connection to <git-repository> <port> port [tcp/*] succeeded!"

If you get:

connect to <git-repository> <port> (tcp) failed: Connection timed out

You need to edit your ~/.ssh/config file. Add something like the following:

Host example.com
Port 1234

I was having this same issue, but the answer I found was different, thought someone might come across this issue, so here is my solution.

I had to whitelist 2 IPs for port 22, 80, 443, and 9418:

  • 192.30.252.0/22

  • 185.199.108.0/22

In case these IP's don't work, it might be because they got updated, you can find the most current ones on this page.


Quick workaround: try switching to a different network

I experienced this problem while on a hotspot (3/4G connection). Switching to a different connection (WiFi) resolved it, but it's just a workaround - I didn't get the chance to get to the bottom of the issue so the other answers might be more interesting to determine the underlying issue


The answer above gave me the information needed to resolve this issue. In my case the url was incorrectly starting with ssh:///

To check the url in your git config is correct, open the git config file :-

git config --local -e

Check the url entry. It should NOT have ssh:/// at the start.

Incorrect entry:

 url = ssh:///git@github.com:username/repo.git

Correct entry:

 url = git@github.com:username/repo.git

If your url is correct, then the next step would be to try the answer above that suggests changing protocol to http.


Need Your Help

Mutiple hubs connection over one signalR request

asp.net-mvc signalr signalr.client

I am working on a MVC application using asp.net which contains 4 portion which need to be updated in real-time.