55

I want to push a repo from my computer to GitHub. I set the remote origin

git remote add origin git@github.com:alicht/tweetanuber.git

and then after when I try pushing to GitHub

git push -u origin master

I'm greeted with this error:

ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

How can I resolve this issue and push the repo on my local computer to GitHub?

alicht
  • 739
  • 2
  • 6
  • 11
  • 1
    Did you configure your SSL settings using something like the Git tutorial? The error message says that it's either an authentication problem, or the repo does not exist (and you can rule out the latter easily by going to GitHub and checking). – Tim Biegeleisen Feb 22 '16 at 16:28
  • Yep- I followed the git tutorial exactly and yet this is the error message I'm getting – alicht Feb 22 '16 at 16:33
  • 1
    Maybe you could also post a summary of what you've done from the SSL point of view to help someone reading your question. – Tim Biegeleisen Feb 22 '16 at 16:37
  • Would be happy to- but can you please clarify what you'd like me to post? – alicht Feb 22 '16 at 16:39
  • See if you have blocked it on any firewall in between, i.e. try if you can `telnet github.com 22` or if this gives a connection error as well. – Martin C. Feb 22 '16 at 19:02
  • There can be a possibility that Local Network admins disabled the website, like I tried to push code while in conference but got same error, tried with hotspot worked – Abhishek Thapliyal Jan 12 '23 at 07:16

9 Answers9

102

I have had this same problem the solution was edit ~/.ssh/config and put this lines:

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

If there is no file config in this folder, simply create one.

Lukasz
  • 3
  • 2
  • 18
    This configures your SSH client to use github's ssh server on port 443 rather than the standard port 22. 443 is usually not blocked because it is normally used for SSL traffic https://help.github.com/en/articles/using-ssh-over-the-https-port – sguha May 26 '19 at 10:20
  • 1
    For gitlab.com the Hostname is altssh.gitlab.com See: https://docs.gitlab.com/ee/user/gitlab_com/#alternative-ssh-port – Vivian Oct 05 '21 at 13:41
  • 1
    for some reason my server is blocking all outbound 22, so this worked, i will work out why blocked now... – Hayden Thring Mar 16 '23 at 20:04
38

That indicates that the git software cannot connect to Github through SSH: this often happens if your firewall, or the firewall set up by your ISP, blocks SSH connections on port 22. A quick workaround to see if this is the problem is to try the HTTPS URL provided by Github:

git remote add origin-https https://github.com/alicht/tweetanuber.git
git push -u origin-https master

If that works, then it's definitely your SSH port being closed. You could continue to use this alternate syntax, try to get port 22 unblocked on your computer or at your ISP, or check out the suggestion at https://stackoverflow.com/a/8081292/27310 and see if that works for you.

Community
  • 1
  • 1
Gaurav
  • 1,888
  • 1
  • 18
  • 23
8

The reason could be the firewall modification as you are under a network.(In which case they may deliberately block some ports): Which in my case I'm on the library and the firewall is blocking. For this work's do on terminal:

git config --local -e

and change this(using vim you need to type the keyboard 'i' for insert):

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

for this:

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

Then for save(type the keyboard ESC and then type wq! and Enter).

Then try to push again.

rld
  • 2,603
  • 2
  • 25
  • 39
4

One of possible issues is network. To verify this check if outbound port 22 is open:
netcat nc -v portquiz.net 22 or with telnet telnet portquiz.net 22
Sample output for port 22

nc: connectx to portquiz.net port 22 (tcp) failed: Operation timed out

Sample output for port 80

found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
    outif en4
    src 192.168.0.103 port 55443
    dst 5.196.70.86 port 80
    rank info not available
    TCP aux info available

Connection to portquiz.net port 80 [tcp/http] succeeded!

tip about portquiz from Link

Possible solutions:

  • Change git config Link
  • Use VPN
  • Use mobile hotspot
  • Open port 22
xab
  • 636
  • 7
  • 11
3

It's due to my network, it was blocking the call. When I switched to my hotspot it started working!!

Saravanan
  • 566
  • 5
  • 13
1

This was driving me crazy. Most likely the port 22 is blocked either by your firewall or your provider. Quick workarround is to change from git@github.com:USERNAME/REPO.git to **ssh://git@ssh.github.com:443**/USERNAME/REPO.git

Jim
  • 2,760
  • 8
  • 42
  • 66
0

I was baffled by a similar error:

Connection timed out during banner exchange
Connection to UNKNOWN port 65535 timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

It had worked fine before. I got similar messages no matter which repository I tried to pull from or push to. I solved it by rebooting my local machine.

Zachary Drake
  • 1,356
  • 1
  • 8
  • 12
-1

There may be something wrong with your firewall, I met the same problem before and I changed the remote connection method from ssh to url and fixed it.

git remote set-url origin https://...
git remote set-url --push origin https://...

After that, you can continue to push it.

Sizhe Wei
  • 1
  • 1
-9

For me the below worked.

git checkout master
git fetch
git pull
git checkout branchName
git pull
ss301
  • 514
  • 9
  • 22