alicht
alicht

Reputation: 809

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

Upvotes: 62

Views: 168097

Answers (11)

Judith lobo
Judith lobo

Reputation: 267

navigate to C:\Users<username>\ .ssh

edit or create config file

Host <host URl> 
User git
Port <port>

run ssh -vT

Upvotes: -1

Adnan Amman Ullah
Adnan Amman Ullah

Reputation: 56

For me, removing the authHost and port from know_hosts worked.

The error was:

Received disconnect from **.**.*.22 port **99:2: Detected AuthTimeout after 120600/120000 ms.
Please make sure you have the correct access rights
and the repository exists.

I removed this **.**.*.22 port **99 from known_hosts file and did the git command again and it worked.

Upvotes: 0

Rafael
Rafael

Reputation: 5

Maybe the problem is with the version of openSSH and openSSL that you have installed.

Communication with GitHub only works for me with the versions:

OpenSSH_7.6p1, OpenSSL 1.0.2u 20 Dec 2019

You can find them at:

openssl:

https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz

openssh:

https://www.openssh.com/portable.html

https://ftp.rnl.tecnico.ulisboa.pt/pub/OpenBSD/OpenSSH/portable/openssh-7.6p1.tar.gz

prerequisites

$ sudo apt install libssl-dev
$ sudo apt install zlib1g-dev libz-dev
# install OpenSSL < 1.1.0
# ------------------------
$ tar -xvf openssl-1.0.2u.tar.gz
$cd openssl-1.0.2u
$./config
$ sudo make install

# install openssh-7.6
# --------------------
$ tar -xvf openssh-7.6p1.tar.gz
$cd openssh-7.6p1
$ ./configure --without-zlib-version-check exec_prefix=/usr --without-openssl-header-check -with-ssl-dir=/usr/local/ssl
$ sudo make
$ sudo make install

Upvotes: 0

Saravanan
Saravanan

Reputation: 911

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

Upvotes: 6

Zachary Drake
Zachary Drake

Reputation: 1404

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.

Upvotes: 0

Guilherme Nunes Fontans
Guilherme Nunes Fontans

Reputation: 1351

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.

Upvotes: 125

Jim
Jim

Reputation: 2828

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 [email protected]:USERNAME/REPO.git to **ssh://[email protected]:443**/USERNAME/REPO.git

Upvotes: 1

Sizhe Wei
Sizhe Wei

Reputation: 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.

Upvotes: -1

xab
xab

Reputation: 1236

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

Upvotes: 4

rld
rld

Reputation: 2763

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

Upvotes: 10

Gaurav
Gaurav

Reputation: 1918

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.

Upvotes: 40

Related Questions