Yefim Blokh
Yefim Blokh

Reputation: 85

Multiple error when trying to push to remote repository

after coding up a javascript project, I wrote

git push -u origin main

however it gives me back:

ssh: connect to host github.com port 22: Undefined error: 0
fatal: Could not read from remote repository.

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

pic to describe it

What should I do? Im new to git/github in general and have been trying to solve it with out luck. Thank you to all the answers in advance

Upvotes: 0

Views: 1115

Answers (4)

codebox
codebox

Reputation: 20254

Another data point for anyone else struggling with this.

I was getting the same ssh: connect to host github.com port 22: Undefined error: 0 error for all ssh connections, not just github. I tried the various fixes listed above but nothing helped.

Then I tried a reboot and the problem went away so it looks like an OS bug. I'm on an M1 Mac running Sonoma 14.4.1

Upvotes: 0

kernel64bits
kernel64bits

Reputation: 1

I can confirm that this ssh issue is still present on MacOS 14.3.1 & iOS 17.3.1.

Removing AddressFamily inet from ~/.ssh/config also solved it

Upvotes: 0

bric3
bric3

Reputation: 42283

The issue does not seem to be the same as the OP, but the symptoms are very similar, and I'm sharing the solution to my issue. I.e git operations like fetching failed with

ssh: connect to host github.com port 22: Undefined error: 0
fatal: Could not read from remote repository.

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

At the time I was on macOs Sonoma (14.1), on my phone's personal hotspot.

Debugging the connection didn't help much

$ ssh -vT [email protected]
OpenSSH_9.4p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/ME/.ssh/config
debug1: /Users/ME/.ssh/config line 11: Applying options for *
debug1: /Users/ME/.ssh/config line 26: Deprecated option "useroaming"
debug1: /Users/ME/.ssh/config line 29: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: auto-mux: Trying existing master
debug1: Control socket "/tmp/ssh_mux_ssh.github.com_22_git" does not exist
debug1: Connecting to ssh.github.com port 22.
ssh: connect to host ssh.github.com port 22: Undefined error: 0

My ssh config is configured to "multiplex ssh connection via ControlMaster, so if there's no control socket it should create one, and it just fails too.

When going back to my regular wifi hotspot, the ssh command worked flawlessly. The ssh command only failed when connected to my phone's personal hotspot.

Also, I found out that SSH connection was failing on any host when on my personal hotspot. Yet it was possible to establish a TCP connection on the host (via netcat), e.g. ssh.github.com on port 22.

$ nc -w 1 "140.82.121.35" 22
SSH-2.0-babeld-f8b1fc6c

And after "bisecting" the ~/.ssh/config I found the key AddressFamily inet was the cause. I'm not sure why it was an issue since there's an A record for ssh.github.com.

So the fix was, either

  Host *
-   AddressFamily inet

Or

  Host *
-   AddressFamily inet
+   AddressFamily any

Note the UseRoaming settings had no incidence in this issue.

Upvotes: 3

Jake Worth
Jake Worth

Reputation: 5852

When connecting to GitHub via SSH, ensure that you have uploaded an SSH key to GitHub. This article explains the process.

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

Upvotes: 1

Related Questions