25

I'm very new to github, I started using it about two weeks ago. Everything worked perfectly, I was able to push and pull from my remote repository. Today, however, when I tried to pull from it I got this error message:

ssh_exchange_identification: read: Connection reset by peer
fatal: Could not read from remote repository.

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

When I try to do anything that connects to my remote github repository (push, pull, fetch, etc), in fact, it gives me back the same error.

When I type in this command: "ssh -T git@github.com", I just get:

ssh_exchange_identification: read: Connection reset by peer

I didn't modify any settings in my repository or in my SSH keys or anything so I have no idea why it stopped working all of a sudden. What could be the problem?

phd
  • 82,685
  • 13
  • 120
  • 165
forblaze13
  • 281
  • 1
  • 3
  • 3
  • 8
    Execute `ssh -vvv -T git@github.com`, it will show debug information about the connection. – Gonzalo Matheu Feb 09 '19 at 23:35
  • @GonzaloMatheu, I executed it and it returned this (I'll split it into two comments because of the character limit): OpenSSH_7.7p1, OpenSSL 1.0.2p 14 Aug 2018 debug1: Reading configuration data /c/Users/b/.ssh/config debug1: /c/Users/b/.ssh/config line 2: Applying options for github.com debug1: Reading configuration data /etc/ssh/ssh_config debug2: resolving "github.com" port 22 debug2: ssh_connect_direct: needpriv 0 debug1: Connecting to github.com [192.30.253.113] port 22. debug1: Connection established. debug1: identity file /c/Users/b/.ssh/id_rsa type 0 – forblaze13 Feb 09 '19 at 23:43
  • debug1: key_load_public: No such file or directory debug1: identity file /c/Users/b/.ssh/id_rsa-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_7.7 ssh_exchange_identification: read: Connection reset by peer – forblaze13 Feb 09 '19 at 23:44
  • This question might help -> https://unix.stackexchange.com/questions/321968/trying-to-ssh-into-server-and-getting-key-load-public-no-such-file-or-directory – Gonzalo Matheu Feb 09 '19 at 23:56
  • I didn't understand much from it, could you please explain the solution provided there? It seems it's for a different context than github. – forblaze13 Feb 10 '19 at 02:35
  • I have already answered here: https://stackoverflow.com/a/64100419/3437897 – Ghulam Akbar Sep 28 '20 at 10:40

18 Answers18

22

I had a similar issue recently, I'm not sure whether its exactly the same as I got the connected user by following command.

ssh -T git@gitlab.com

But when I try to push the code to remote repository I got same error.

kex_exchange_identification: read: Connection reset by peer
fatal: Could not read from remote repository.

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

After trying few solutions from the internet without success, I just tried git init and it worked for me. I hope this works only if the connection user has bound correctly.

Try it out Good Luck.. :)

Kandy
  • 1,067
  • 12
  • 29
18

I also had this problem and I was able to fix it by restarting my internet connection.

I was so confused when git bash suddenly gave me that message. I did not do any alteration on my git repositories at all. Restarting my connection fixed it.

dhaynamicoGrant
  • 181
  • 1
  • 5
  • Same here. Switched to mobile bec my fiber was down and got this error suddenly for no apparent reason. So, the problem wasn't git. – duduwe Oct 07 '22 at 10:05
9

Do git-init. It will reinitialize the connection

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Nitishgarg
  • 109
  • 1
  • 2
4

The same thing happened to me with Bitbucket today. I first tried git init as another reply suggested. No luck. Then simply enough, I just rebooted my PC and it all started working again.

Onur D.
  • 515
  • 3
  • 11
  • I have been trying to push to git from terminal. Simply, closing and than reopening the terminal has solved the case. – ni8mr Mar 20 '22 at 08:16
3

I had the same thing and this worked for me:

git config http.sslVerify "false"

And then:

git remote rename origin old-origin

and then instead of using ssh (git@YOUR_GIT_REPO.git) used the https url and set that as origin:

git remote add origin https://YOUR_GIT_REPO.git
rolhai123
  • 59
  • 2
  • 6
3

I got this error today and wondered what had gone wrong. Rebooted. Still bad. Then I went to gitlab website and got a 503 Error indicating server unavailable. gitlab was doing major maintenance on their site and said would be down for two hours.

I'm just posting this in case others have this problem. In this case it was not a local problem but the remote git server. The git bash error message is quite cryptic. It said:

kex_exchange_identification: read: Connection reset by peer
Connection reset by 2606:4700:90:0:f22e:fbec:5bed:a9b9 port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
David Casper
  • 394
  • 2
  • 9
1

In my case was because the ssh port at /etc/ssh/ssh_config file was changed. Once I changed the port in /etc/ssh/ssh_config back to 22, I was able to connect to Gitlab.

Cristian Zumelzu
  • 842
  • 10
  • 15
1

The access point you are using might be blocking certain type of communication. I just faced the problem while using my university's wifi network and when I changed the connection to my mobile's service it worked just fine

Osama Heba
  • 29
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '22 at 11:16
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31400372) – tjheslin1 Mar 31 '22 at 06:23
  • No I do not have a question. I was suggesting that the person with problem should make sure that the internet network s\he is using is not blocking certain traffic protocols – Osama Heba Apr 01 '22 at 07:09
  • 2
    In my case this did answer the question. The connection to the server over port 22 (I suspect) was being blocked by my company's VPN, so disabling the vpn did resolve the issue. – Kyle Aug 03 '22 at 14:25
1

I have also faced this problem and I was unable to push anything to Github or even ssh into my Linux servers. After days of troubleshooting and researching, I realised it was to do with the internet connection I was connected to. When I connected to a different network (From a different provider), I was able to proceed normally with pushing to GitHub and SSH-ing to the Linux servers. Try to change your internet connection i.e to a different router/provider e.t.c and see if it also works for you.

  • 1
    Thanks! Didn't realize I had my wifi enabled and was having wifi issues. Disabled to use my landline and it instantly worked! – Snekse May 26 '23 at 14:51
0

I have resolved this error after a lot of struggle but I think its a dumb idea but it will work.

  • Go to your git projects and clone it by HTTP link in your system.
  • After you will get the git folder in your cloned project.
  • copy that git folder and replace it with your SSL error showing project.
  • then as usual git add. and so on .it will push normally.

Enjoy!

0

I also got same error. But after deleting .git file it works fine but somehow repeated again and again..

kex_exchange_identification: read: Connection reset by peer Connection reset by 13.234.210.38 port 22 fatal: Could not read from remote repository. Please make sure you have the correct access rights. and the repository exists.
phuclv
  • 37,963
  • 15
  • 156
  • 475
satyendra singh
  • 479
  • 1
  • 4
  • 5
0

I was facing the problem because I got connected to one of the VPN

user2694064
  • 357
  • 2
  • 4
  • In my case for bitbucket, i have to turn on my VPN on my Mac OS, so this can be also bug from my VPN application. – Rhony Jun 03 '22 at 03:19
  • In my case this answered the question. The connection to the server over port 22 (I suspect) was being blocked by my company's VPN, so disabling the vpn resolved the issue – Kyle Aug 03 '22 at 14:25
0

I had this issue because I had incorrectly added a new remote repo (called origin) to my local git repo copy. You can view all your remotes like so:

$ git remote -v
origin  git@my-host.com:1234/my-path/my-project.git (fetch)
origin  git@my-host.com:1234/my-path/my-project.git (push)

Notice how the protocol (ssh://) is missing. This was causing the error for me. So just delete the old remote repos:

$ git remote rm origin
$ git remote -v
# empty

Then add the correct remote repo (called origin):

$ git remote add origin ssh://git@my-host.com:1234/my-path/my-project.git
$ git remote -v
origin  ssh://git@my-host.com:1234/my-path/my-project.git (fetch)
origin  ssh://git@my-host.com:1234/my-path/my-project.git (push)
mulllhausen
  • 4,225
  • 7
  • 49
  • 71
0

I had to flush dns to resove this problem.

On Windows or WSL, open a admin powershell and execute ipconfig /flushdns. Then reboot WSL with wsl.exe -t Ubuntu and maybe the whole PC.

Charles Attend
  • 51
  • 1
  • 1
  • 4
0

My case is same with @osama-heba in his answer.

The solution is to change port. If it is 22, try to change to 443 and vice-versa.

  1. In ubuntu, change the port on:

    sudo nano ~/.ssh/config
    
  2. Try remove origin and add it again (here, I use GitHub for example),

    git remote rm origin
    git remote add origin git@github.com:USERNAME/REPONAME.git
    
  3. To test and initilaize connection, you can push or pull from the remote. Alternatively in GitHub, use:

    ssh -T git@github.com
    
Muhammad Yasirroni
  • 1,512
  • 12
  • 22
0

None of these worked for me: restart wifi card, git init. I did not try rebooting.

I only see this problem when using IDE like PyCharm, and only since a couple of months.

In my case I have about 20 git repos hosted in github. If I only update a small number of git repos, the problem does not occur.

A web search indicates github does not throttle git fetch, but maybe it's a recent change that hasn't been announced yet?

Oliver
  • 27,510
  • 9
  • 72
  • 103
-1

This same problem also happened to me on my bitbucket repository, all I did was delete this repository and create another one with another name, and in locla I only modified the url of remote

git remote set-url origin git@bitbucket.org:USERNAME/REPOSITORY.git

To find out more about changing the URL of your repository, click on the link here : changing-a-remotes-url

-1

On Ubuntu + VSCode Terminal and using Bitbucket:

Restarting didn't work.

Reinitialize the repo worked:

$ git init
Nisal Gunawardana
  • 1,345
  • 16
  • 20