430

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.

8
  • 25
    Create a hotspot on your mobile device, connect via your mobile device, then git push. Worked for me.
    – zundi
    Sep 12, 2017 at 19:19
  • 1
    For Jenkins, see: Why is Jenkins failing when fetching from git?
    – kenorb
    Jul 29, 2019 at 22:17
  • 5
    The same problem happened to me in the UK with Virgin Media. I tried to push/pull to GitHub via ssh at home and no luck but at work was fine. So I realised that I got problems with my ISP. The simple fix for me was to use Cloudflare DNS 1.1.1.1 instead of a default one that's why @zundi succeed through a mobile hotspot. Mar 18, 2020 at 12:59
  • 4
    This worked for me -> gist.github.com/Tamal/1cc77f88ef3e900aeae65f0e5e504794
    – Imran
    May 3, 2021 at 18:41
  • Very weird! But I closed my Postman and it solved it!!! 😁 (Win10)
    – aderchox
    Dec 14, 2021 at 21:06

32 Answers 32

800
+50

For me none of the suggested solutions worked so I tried to fix it myself and I resolved it. I was getting this error on my AWS EC2 UBUNTU instance. I edited the ssh config (or add it if it does not exist).

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.

19
  • 11
    This solution worked fine for me, although it didn't solve the issue for GitLab. In that case, please consider that GitLab.com runs a second SSH server that listens on the commonly used port 443, which is unlikely to be firewalled. All you have to do is edit your ~/.ssh/config and change the way you connect to GitLab.com. In that case, see this article: about.gitlab.com/2016/02/18/… Dec 5, 2018 at 3:14
  • 3
    Hi, i had a same problem, my router is from NET and him block the 22 port. That config solved my problem definitely Jan 14, 2019 at 17:40
  • It is not git config but ssh config
    – GuyT
    Aug 27, 2019 at 4:26
  • 5
    After hours of finding anwers... you're CHAMP, anyway why do we need to change github.com to ssh.github.com? I still don't get it Nov 20, 2019 at 22:40
  • 1
    All of a sudden github stopped working for like half my repos, but worked for others. This solutions works
    – konung
    Oct 5, 2023 at 14:43
342

The reason could be the firewall modification since you are on a network, in which case they may deliberately block some ports.

To double check if this is the reason, run:

ssh -T [email protected]

This should timeout. If that's the case, then use the http protocol instead of ssh. Change your url in the config file to http:

git config --local -e

and change:

 url = [email protected]:username/repo.git

to

url = https://github.com/username/repo.git
11
  • 17
    I had that issue once, but restarting my computer solved it.
    – Kevin Lee
    Jan 9, 2016 at 17:20
  • 3
    fatal: unable to access 'gitlab.com:******.git/': Port number ended with 'f'
    – Fakher
    Sep 5, 2017 at 14:06
  • 45
    using https instead for ssh is not the right solution. There must a way to set proxy in git config and in ssh settings to solve this.
    – shijin
    Dec 1, 2018 at 15:49
  • 7
    This disables using the ssh key, doesn't it?
    – Jason
    Jun 7, 2019 at 13:24
  • 17
    Virgin Media UK has a child safe mode, which I had to disable. Oct 3, 2019 at 14:54
78

Create a config file in the .ssh folder:

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
4
  • 2
    See Mahan_F answer for detailed explanation on why this happens.
    – refaelio
    Mar 18, 2019 at 14:48
  • 3
    This is the only thing that worked for me on GitLab. Thanks, Isaque!
    – awwsmm
    Jul 24, 2019 at 8:20
  • Thank you, I finally managed to set up github on a cPanel.
    – Mike
    Aug 9, 2021 at 13:35
  • The details from Mahan_F are here: stackoverflow.com/a/52817036/1603480 Aug 16, 2021 at 7:18
52

Basic URL Rewriting
Git provides a way to rewrite URLs using the git config. Run:

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

Now, all git commands will perform a substitution of git:// to https://

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

4
  • 2
    Thanks! Ours was during the Jenkins build so I couldn't manually edit the git file (I don't have the git credentials for the jenkins account) - so this was very useful.
    – Phil
    Mar 27, 2015 at 15:32
  • 2
    This is great. I've added git aliases for each to easily switch Mar 31, 2015 at 23:59
  • 20
    Concerning github, the command should be: git config --global url."https://github.com/".insteadOf [email protected]:. Notice the differences: @ becomes // and : becomes /.
    – Frodon
    Jan 21, 2016 at 14:38
  • 4
    Is this just replacing SSH with HTTPS ? This is no real solution.
    – Chris Neve
    Mar 16, 2021 at 13:16
23

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!

4
  • I particularly had to add Hostname and Port lines to my config, and viola, it works now.
    – Rafs
    Sep 22, 2021 at 12:11
  • 2
    @Animesh Singh what is <proxy-Host>:<port> here ?? Mar 18, 2022 at 7:16
  • @Animesh Singh is it github.com:443 am i right ? Mar 18, 2022 at 7:17
  • 2
    If proxy requires authentication: adangel.org/2020/10/15/github-behind-proxy
    – Juan Rojas
    Jan 20, 2023 at 22:07
19

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

1
  • 3
    I switched from the WiFi to the 4G and it worked. I don't understand either.
    – Adam Casey
    Feb 13, 2019 at 17:31
9

For me, the problem was from my Internet Service Provider (ISP) -- port 22 (ssh) was not enabled. So I asked them to enable the port on the network and it started working.

To see if this is the issue, connect to your mobile hotspot and run:

ssh -T [email protected] or git pull
If it works, then ask your ISP to enable port 22.

1
  • This resolved the issue for me. Switched to a 4G hotspot and git push worked. But I turned off the hotspot, switched back to the old network...and now git works again. Who knows?
    – AlainD
    Jan 25, 2022 at 17:07
9

Try

ssh -T -p 443 [email protected]

instead of

ssh -T [email protected]

1
  • 5
    what does it mean if even this fails? Apr 4, 2022 at 17:43
7

This answer is based on the comment to the main question from @zundi (to whom credit should go, thanks zundi):

  • Create a hotspot on your mobile device and connect to the hotspot
  • git push
  • Turn off the hotspot on your mobile device and reconnect to the original network
  • git push continues to work

I do not know why temporarily connecting to a hotspot magically "kickstarts" the original network connection.

4

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
1
  • 7
    I'm not sure everyone is going to have nc installed. What is that supposed to be? Netcat or something?
    – Hack-R
    Apr 8, 2018 at 21:55
4

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

3

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.

1
  • 1
    How did you add them into a whitelist?
    – Watanabe.N
    Mar 24, 2022 at 5:05
3

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.

2

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

1
  • 2
    I think ssh config --local -e should actually be git config --local -e, can you please check? Feb 23, 2023 at 10:06
2

I had this issue when working over a public library's wifi.

Running PowerShell test-netconnection github.com -port 22 showed that they were blocking outbound connections on that port (lots of places seem to only allow HTTP ports; i.e. 80 and 443).

Thankfully, GitHub allows you to access SSH over port 443 too: documentation

Instead of running git clone [email protected]:myOrg/myRepo.git, make the following tweaks:

  • Add ssh:// to the start of the URL
  • Connect to the ssh subdomain (i.e. ssh.github.com instead of just github.com)
  • Add the port after the hostname: i.e. :443.
  • Amend the colon before your org/username to a slash.

So for the above example you'd run: git clone ssh://[email protected]:443/myOrg/myRepo.git

This may give you a warning about the authenticity of the host; but (assuming you're happy*), answering YES to that will allow the command to run. To decide if you should answer YES, check the fingerprint given in this warning against GitHub's published fingerprints.

2

I had the same problem and it seems like something changed on my ISP. I will leave my solution here for future reference. At first I checked my gitconfig.

$ cat ~/.gitconfig
[user]
    name = ****
    email = ***@***.com
[url "[email protected]:"]
    insteadOf = https://github.com

As it explains my requests from git clients are forwarding to [email protected]:, I tried to ping with the server with ssh.

$ ssh -T [email protected]
ssh: connect to host github.com port 22: Connection timed out

So, I appears that I can not connect to host github.com from my machine. So, I tried to connect the ssh port instead. This time connection was successful.

$ ssh -T -p 443 [email protected]
Hi raihankhan! You've successfully authenticated, but GitHub does not provide shell access.

So, I changed my ~/.gitconfig like the following and git push/pull/clone requests were back to working state!

[user]
    name = *****
    email = ***@*****.com

[url "ssh://[email protected]:443/"]
    insteadOf = [email protected]:
1

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.

1

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
1

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

1

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

1

For my case, I didn't change anything in my PC. My workaround was:

  • Restart the PC.
  • Connect PC network with mobile hotspot or use Cloudflare WARP for private network.
  • Do your work and chill :D
1

If your ssh -T [email protected] connects and does not time out but you're still getting the error when trying to git commit:

ssh: connect to host sign port 22: Operation timed out?

fatal: failed to write commit object:

Ive been able to fix the issue by disabling gpgsign in .gitconfig

[commit]
    gpgsign = false

Running MacOs, Not under proxy. Im guessing the complete solution is to generate and re assign new gpg keys but ive been at this for hours so perhaps tomorrow.

0

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.

0

Refreshing my Internet connection worked for me.

Also if you use mobile hotspot - restart of mobile device was solution in my case.

1
  • 5
    git: 'reload' is not a git command. See 'git --help'. Sep 24, 2021 at 16:37
-1

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

-1

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.

1
  • That sets the Kex Algm to just the (comma-separated) arguments. If you want to add some kex, you can prepend to the default list by starting your arguments with ^ like ^nist1,ed25519,etc. + will append to and - will remove from the default list. Feb 23, 2023 at 15:22
-1

If you are in windows, move into the directory where you stored your ssh key, and try again, it worked for me.

-1

What solved it for me was doing ssh-add on the key file.

ssh-add C:/Path/To/Key.pem

C:/Users/User/.ssh/config:

Host sshapp
    Hostname ssh.github.com
    IdentityFile C:/Path/To/Key.pem
    Port 443

Then clone using:

>git clone git@sshapp:<git_user>/app.git
Cloning into 'app'...
The authenticity of host '[ssh.github.com]:443 ([140.82.121.35]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6T.....vCOqU.
-1

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.

-1

In my case,

  1. I backup the known_hosts to known_hosts.bk
  2. I clear all content of the old known_hosts.

Maybe it did remember the old host when I ssh using the other .pem file.

  • Error

enter image description here

  • Success

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.