Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

ssh

People also ask

Why is SSH connection timed out?

This error message comes from the SSH client. The error indicates that the server didn't respond to the client and the client program gave up (timed out). The following are common causes for this error: The security group or network ACL doesn't allow access.


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.


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 [email protected]

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

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

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 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!


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


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