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

GitSsh

Git Problem Overview


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.

Git Solutions


Solution 1 - 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 ssh 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 [email protected] 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.

Solution 2 - Git

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 = [email protected]:username/repo.git

to

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

Solution 3 - Git

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: https://stackoverflow.com/questions/4891527/git-protocol-blocked-by-company-how-can-i-get-around-that/10729634#10729634

Solution 4 - Git

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

Solution 5 - Git

I faced the same problem and couldn't find a working solution. I faced this problem while setting up a local server and the git couldn't connect through my proxy network but my workstation could. This was the output when I ran the command ssh -vT [email protected]

ubuntu@server:~$ ssh -vT [email protected]
OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /home/ubuntu/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [13.234.176.102] port 22.

So I tried using an SSH connection made over the HTTPS port by editing the config file ~/.ssh/config but to no avail.

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

Finally, I found this [article][1] which solved and exposed the real problem.

# github.com
Host github.com
    Hostname ssh.github.com
    ProxyCommand nc -X connect -x <PROXY-HOST>:<PORT> %h %p
    Port 443
    ServerAliveInterval 20
    User git

This is my config file and now git works perfectly well through ssh!
[1]: https://pcarleton.com/2016/11/10/ssh-proxy/

Solution 6 - Git

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

Solution 7 - Git

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

Solution 8 - Git

For me, the problem was from ISP side. The Port number was not enabled by the Internet Service Provider. So asked them to enable the port number over my network and it started working.
Only to test: Connect to mobile hotspot and type ssh -T [email protected] or git pull.
If it works, then ask your ISP to enable the port.

Solution 9 - Git

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.

Solution 10 - Git

In a similar failure mode as Ludder, I was getting this error when I hadn't yet signed in to the correct company VPN. :facepalm:

Solution 11 - Git

Ok Try this ssh -T -p 443 [email protected] instead of ssh -T [email protected]

Solution 12 - Git

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:///[email protected]:username/repo.git

Correct entry:

 url = [email protected]: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.

Solution 13 - Git

Changing the repo url from ssh to https is not very meaningful to me. As I prefer ssh over https because of some sort of extra benefits which I don't want to discard. Above answers are pretty good and accurate. If you face this problem in GitLab, please go to their official documentation page and change your config file like that.

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

Solution 14 - Git

Restart the computer solved it for me.
Git version: 2.27.0.windows.1
OS version: Windows 10

Solution 15 - Git

The main reason was the change from the proxy installed by the company recently, which has blocked other ssh connections other than those to the company domain.

I was able to connect successfully by following these steps:

  1. Double checked that the issue is what I am assuming by ssh -T [email protected]

It should end up in a timeout.

  1. Edited the local remote URL by

ssh config --local -e

and from

[email protected]:asheeshjanghu/Journal.git

to

url=https://github.com/asheeshjanghu/Journal.git

The important point is that in the url you have to change at 2 places.

from git@ to https:// and from github:username to github/username

In the end verify by doing a git fetch

Solution 16 - Git

In my case the problem was caused by a setting that I had changed on my Router a day before. So on my Router, I just had to revert the setting Isolation to disable and it has fixed my issue.

enter image description here

Solution 17 - Git

When I accidentally switched to a guest wifi network I got this error. Had to switch back to my default wifi network.

Solution 18 - Git

I had this issue for 2 hours and it turns out removing the "s" from https and just do:

git clone -b <branchName> http:<projecturl>

Fixed it.

Solution 19 - Git

ISSUE: Step to produce issue: git clone [email protected]:sramachand71/test.git for the first time in the new laptop ERROR ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. SOLUTION for the first time in the system to clone we need to give double quotes for the clone command. $ git clone "[email protected]:sramachand71/test.git" i face this issue in the system even after everything was correct but noticed at last that double quote is must for url "repository_url.git" for first time or new user in the system.

Solution 20 - Git

I had this issue on a server of mine that was set up with it's regular IP and a failover IP. The failover IP did not point to the server at this time. I had to remove the failover IP from the server configuration in /etc/netplan/01-netcfg.yaml. Pointing the failover IP to that server would have probably solved the issue as well.

Solution 21 - Git

My computer was unable to connect port 22 while connecting to Github. I never had this issue with bitbucket. If you have both GitHub and bitbucket then

Host bitbucket.org
Hostname  altssh.bitbucket.org
Port  443


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

ref

It basically connects SSH in 443 port instead of 22.

Solution 22 - Git

Suggest to check the Internet connection or connect to another connection.

Solution 23 - Git

So I was having this same problem (not behind a proxy) and came across this question. Here's what I did to fix it:

Tried running ssh -T [email protected] and it did time out, but adding -o KexAlgorithms=ecdh-sha2-nistp521 made a successful connection (found from this answer to a semi-related question).

To permanently fix this, I just added a line KexAlgorithms=ecdh-sha2-nistp521 under github.com in my ~/.ssh/config. Everything seems to work fine now.

Solution 24 - Git

Refreshing my Internet connection and the git reload feature from the terminal worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVihari PiratlaView Question on Stackoverflow
Solution 1 - GitMahan_FView Answer on Stackoverflow
Solution 2 - GitVihari PiratlaView Answer on Stackoverflow
Solution 3 - GitMichaël PView Answer on Stackoverflow
Solution 4 - GitIsaque Elcio View Answer on Stackoverflow
Solution 5 - GitAnimesh SinghView Answer on Stackoverflow
Solution 6 - Gitkip2View Answer on Stackoverflow
Solution 7 - GitameenView Answer on Stackoverflow
Solution 8 - GitAnuView Answer on Stackoverflow
Solution 9 - GitArtur GrigioView Answer on Stackoverflow
Solution 10 - GitMad BernardView Answer on Stackoverflow
Solution 11 - GitGokulView Answer on Stackoverflow
Solution 12 - GitManda QoPView Answer on Stackoverflow
Solution 13 - GitMd. Nowshad HasanView Answer on Stackoverflow
Solution 14 - GitWenfang DuView Answer on Stackoverflow
Solution 15 - GitAsheesh JanghuView Answer on Stackoverflow
Solution 16 - Gituser1941537View Answer on Stackoverflow
Solution 17 - GitLudderView Answer on Stackoverflow
Solution 18 - GitaPurpleDevView Answer on Stackoverflow
Solution 19 - GitShivaprasad RView Answer on Stackoverflow
Solution 20 - GitRobinView Answer on Stackoverflow
Solution 21 - GitktaView Answer on Stackoverflow
Solution 22 - GitTiiGRUSView Answer on Stackoverflow
Solution 23 - GitKlaus HaukensteinView Answer on Stackoverflow
Solution 24 - GitWinnie NyamburaView Answer on Stackoverflow