简体   繁体   中英

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

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?

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.

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.

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.

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

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

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

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.

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.

For me the below worked.

git checkout master
git fetch
git pull
git checkout branchName
git pull

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM