614

I am trying to set git up with http://danielmiessler.com/study/git/#website to manage my site.

I have gotten to the last step in the instructions: git push website +master:refs/heads/master

I am working using the git ming32 command line in win7

$ git push website +master:refs/heads/master
Bill@***.com's password:
Connection closed by 198.91.80.3
fatal: Could not read from remote repository.

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

One problem here may be that the program is looking for Bill@***.com. when I connect via ssh to my site I have a different username( lets say 'abc'). so maybe this should be abc@***.com. If so I don't know how to change this or if I can push under an alias

mudri
  • 758
  • 3
  • 16
user1592380
  • 34,265
  • 92
  • 284
  • 515
  • 2
    I had the same issue, sometimes this error happens when git server isn't reachable or has something like "internal server error". – Morteza Mar 06 '14 at 14:21
  • 6
    First please look at `.git/config` file and see everything is in order. It had wrong set-url and origin values for me. – mixdev Jun 01 '17 at 16:59
  • Perhaps this would solve the issue: https://help.github.com/articles/connecting-to-github-with-ssh/ – Guy Avraham Oct 29 '17 at 06:47
  • A related issue: https://stackoverflow.com/questions/10127818/ssh-exchange-identification-connection-closed-by-remote-host-under-git-bash – Anton Tarasenko May 08 '18 at 08:55
  • can you show me the correct order of .git/config and also the .ssh/config ... coz i'm confused abit tough. – gumuruh Jul 13 '19 at 13:24
  • For me this happened because I was using the wrong type of slashes in the URL. – S2673 Oct 17 '20 at 23:31
  • In my case, I had to turn off my WiFi and turn it back on again. Rest of internet was working, including fast.com, but for some reason no GitHub operations were working. – Joshua Pinter Nov 26 '20 at 21:16
  • For me, SSH works fine in Git Bash (Windows) but not in Powershell or Command prompt. – Ajit Panigrahi Jan 11 '21 at 07:16
  • So many answers. This post resolved my issue for having a work and personnal git account both using SSH https://www.freecodecamp.org/news/manage-multiple-github-accounts-the-ssh-way-2dadc30ccaca/ – Stephane Nov 20 '21 at 13:26
  • In my case I typed the remote url incorrectly. The error is not distinguishable from failed ssh authentication. – John Jiang May 09 '22 at 16:41
  • For me this was caused by the recent change of RSA SSH host key by GitHub. More details can be found [here](https://github.blog/2023-03-23-we-updated-our-rsa-ssh-host-key/). In short, I needed to remove the old GitHub RSA key from ~/.ssh/known_hosts and add the new one. To be on the safe side, it's better to add the key found at the same link above. – Boson Bear Mar 29 '23 at 20:03
  • **If you're using WSL or similar**, make sure your SSH key is in there too... – Andrew Jul 12 '23 at 22:57

62 Answers62

510

Your ssh key most likely had been removed from ssh agent

ssh-add ~/.ssh/id_rsa

where id_rsa is a ssh key associated with git repo

Update

You may get Could not open a connection to your authentication agent. error to resolve that you need to start the agent first by:

eval `ssh-agent -s`
Abdul Baig
  • 3,683
  • 3
  • 21
  • 48
Johnny Cage
  • 5,526
  • 2
  • 11
  • 7
  • 15
    This worked for me! I spent a long time trying to configure my ~/.ssh/config file to use different keys for different hosts, thought that this file was the problem. In the end, it must have been using the right key for the right host, but that key had been "removed". so `ssh-add ~/.ssh/theKeyInQuestion` got me back up and running with this repo, didnt know the key removed, or what "removed" even means but at least I was able to get authenticated again. SSH is a total mystery to me even after months of dealing with authentication issues. ssh agent issues are one more thing to be aware of! – Alex Bollbach Aug 28 '17 at 16:29
  • Thanks a Lot.. This finally worked for me after trying to create, delete, etc the SSH keys into my GitLab account.... Thanks!! – Bms bharadwaj Jul 22 '19 at 13:13
  • This solved my issue. I already have the newly generated ssh key added on the server. This key need to be added !! – Kashan Sep 10 '19 at 09:57
  • 3
    This solved it for me, I don't understand why.. It used to work and all of a sudden not, is there a process that removes the key from the agent, can it happen on accident? – Miguel Stevens Nov 17 '19 at 09:43
  • Why does it happen? It worked all the day but in the evening it stopped to work. This answer helped. – Andrey Semakin Dec 16 '19 at 14:20
  • 7
    In MacBook I use `ssh-add -k ~/.ssh/id_rsa` – Junior Usca Mar 22 '20 at 21:20
  • @MiguelStevens and @Andrey: had the same thing happen after I ran `ssh-keygen`. The fix was to log out and back in. This `ssh-add` solution did not work. – Dan Dascalescu Apr 07 '20 at 23:43
  • 18
    I'm getting `Could not open a connection to your authentication agent.`. – Dan Dascalescu May 31 '20 at 06:12
  • 7
    @DanDascalescu try to use `eval \`ssh-agent -s\`` to start the ssh-agent firstly – liuqi Dec 11 '20 at 07:58
  • 1
    In my case, the key was stored in `id_ed25519.pub` instead of `id_rsa` so running `ssh-add ~/.ssh/id_ed25519` after `eval \`ssh-agent -s\`` worked for me. Thanks for pointing towards the right direction! – codesnerd Jan 14 '21 at 00:58
  • Thanks. This worked for me but not on the first try. Even after trying these commands, making sure I have the correct SSH key in both local repo and Github account and restarting Windows terminal, I still got the same error. I closed the Windows terminal and used Git Bash and everything worked as expected. – Saurabh Misra Jun 29 '21 at 16:03
  • Is there any way to automatically perform this step when instance is turned on. I restarted my instance and previous key was removed. – darth vader Aug 09 '21 at 06:51
  • After updating my MacBook from Big Sur to Monterey, the ssh-agent did not pick up my id_ed25519 key by default, just the id_rsa key. I added it manually and was then able to login as I had done before the upgrade. – rugplots Dec 02 '21 at 12:16
292

I was facing same issue a while ago...

my .git/config had

url = git@github.com:manishnakar/polymer-demo.git

I replaced it with

url = https://github.com/manishnakar/polymer-demo.git 

and it works now:)

Manish Nakar
  • 4,286
  • 1
  • 18
  • 13
166

You can specify the username that SSH should send to the remote system as part of your remote's URL. Put the username, followed by an @, before the remote hostname.

git remote set-url website abc@***.com:path/to/repo
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • 3
    ps , is there a way to add the password in so I don't keep having to type it? – user1592380 Nov 23 '12 at 20:03
  • 21
    edit the file `.git/config` which has the remote url parameter – Sayanee Apr 04 '13 at 09:31
  • @user61629: I know I'm late to the party, but you should consider using private/public key pairs instead of passwords. – code_dredd Apr 22 '16 at 22:06
  • Which user name? Computer username or github username? – Agent Zebra Jan 23 '17 at 21:36
  • 29
    For Github, you always use the username `git`. Example: `git@github.com:mayoff/uiimage-from-animated-gif.git` Github figures out your identity by looking at what SSH key you send. – rob mayoff Jan 24 '17 at 02:38
  • For me, I had followed all the steps mentioned in [Adding new ssh key][1] and rest of the auxiliary links related to this issue. But the issue was network access. Solution - using VPN to access my Github Enterprise. (in my case Georgia Tech VPN for github.gatech.edu) [1]: https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account – Chaitanya Bapat Apr 05 '19 at 23:49
  • @Sayanee: that file only exists in existing repos, not in new ones you're trying to clone. – Dan Dascalescu May 31 '20 at 06:11
  • 1
    It is not clear enough and my guessing about the answer does not work. – SaidbakR May 03 '21 at 21:07
  • Thanks that worked when I changed https to ssh and added git@ to the hostname. Its been killing me finding a fit to this. – SteveG Jun 16 '21 at 07:25
161

Make sure you have correct url in .git/config

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

If it's your first push, you'll need to set up correct upstream

$ git push -u origin master

You can check which key is used by:

$ ssh -vvv git@github.com

The reply should contain something like this:

debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
...
You've successfully authenticated, but GitHub does not provide shell access.

Also it's possible to define rules for ssh in ~/.ssh/config, e.g. based on aliases:

   Host github
      HostName github.com 
      User git
      IdentityFile "~/.ssh/id_rsa"

   Host git
      HostName github.com 
      User git
      IdentityFile "~/.ssh/some_other_id"

You can set connect to different ports, use different username etc. for each alias.

Tombart
  • 30,520
  • 16
  • 123
  • 136
  • 1
    Thank you!! At some point when I cloned my repo, the `url` was set to `https://github.com/user/repo.git` (without `git@github.com`) and so it refused to use my SSH key. Maybe it's because I cloned it using GIthub for Windows originally (?) – Jedidja Apr 30 '15 at 13:00
  • I've had to change `url = ssh://github.com/RaphaelBossek/dev-atlassian-jira-proman.git` to `url = ssh://git@github.com/RaphaelBossek/dev-atlassian-jira-proman.git` and it worked again – Raphael Bossek Sep 03 '16 at 20:21
  • Damnit, you are awesome. I tried so many other solutions. My url was https: as well :( – agrublev Mar 07 '17 at 21:55
  • The `-vvv` hint was helpful for me. Now I see that it's saying "Connection closed by XXX.XXX.XXX.X port 22". – Ryan Jan 09 '18 at 13:48
  • Ahhh, DeployHQ says "BitBucket is currently experiencing minor service problems. Please check their status page for more information. https://status.bitbucket.org" Bingo. – Ryan Jan 09 '18 at 13:51
  • The [official documentation](https://help.github.com/articles/using-ssh-over-the-https-port/) helped me set the correct port and URL for GitHub access via SSH – Xavier Lowmiller Feb 26 '18 at 09:59
  • What if you're trying to clone a repo? There's no `.git/config`. – Dan Dascalescu May 31 '20 at 06:13
  • @DanDascalescu Then simply check that your're not cloning a `https://...` URI to the repo (the ssh config then doesn't apply). – Tombart Jun 01 '20 at 07:33
  • Perfect, thank you for this answer, I indeed had only `Host github.com` settings defined in `~/.ssh/config` while I was trying to access `gitlab.com` already – RAM237 Aug 22 '22 at 19:51
34

I had a wrong ssh private key for Bitbucket along with the right one in ssh agent.

Deleted all keys first

ssh-add -D

Then added just the right key.

ssh-add ~/.ssh/id_rsa
Foreever
  • 7,099
  • 8
  • 53
  • 55
29

Make sure ssh-agent is running by executing the following command on your terminal:

eval $(ssh-agent -s)

Source: Github documentation

Roberto Ferraz
  • 2,511
  • 24
  • 43
user3362907
  • 299
  • 3
  • 3
28

Try removing the GIT_SSH environment variable with unset GIT_SSH. This was the cause of my problem.

CB.
  • 532
  • 1
  • 4
  • 11
Scott Lindner
  • 589
  • 6
  • 7
  • 1
    Works.. I wonder where I got GIT_SSH environment variable from :) – StrangeLoop Feb 13 '15 at 08:40
  • 1
    For windows remove GIT_SSH environment variable from advanced options menu. Worked for me. – splintercell May 10 '16 at 00:47
  • How? What do I write in the terminal to do that? – Agent Zebra Jan 23 '17 at 21:39
  • Fixed the issue for me as well – GalAbra Nov 02 '20 at 09:28
  • Fixed it for me too. But why does this cause the problem in the first place? – wilmol Jun 17 '21 at 03:06
  • This fixed it for me as well. I use Cygwin as my preferred terminal. It has its own ssh.exe file which is configured properly and works fine. I suspect Cygwin looks for the GIT_SSH variable and will use that if it's there. I recently installed Git onto my Windows machines (as opposed to only having it inside of Cygwin). The Git installer set GIT_SSH to use Plink.exe, which probably wasn't configured as my Cygwin was. Once I removed GIT_SSH, Cygwin returned to normal. – Tanoro Nov 28 '22 at 15:14
28

This is usually caused due to the SSH key is not matching with the remote.

Solutions:

  1. Go to terminal and type the following command (Mac, Linux) replace with your email id.

    ssh-keygen -t rsa -C "you@email.com"

  2. Copy the generated key using following command starting from word ssh.

    cat ~/.ssh/id_rsa.pub

  3. Paste it in github, bitbucket or gitlab respective of your remote.
  4. Save it.
Bastin Robin
  • 907
  • 16
  • 30
19

I had the same problem.

This error means that you have not specified your remote URL location upon which your code will push.

You can set remote URL by 2 (mainly) ways:

  1. Specify remote URL via executing command on Git Bash.

    • Navigate to your project directory

    • Open Git Bash

    • Execute command:

      • git remote set-url origin <https://abc.xyz/USERNAME/REPOSITORY.git>
  2. Mention remote URL direct in config file

    • Navigate to your project directory

    • Move to .git folder

    • Open config file in text editor

    • Copy and paste below lines

      • [remote "origin"] url = https://abc.xyz/USERNAME/REPOSITORY.git fetch = +refs/heads/*:refs/remotes/origin/*

For more detailed info visit this link.

Pratik Patel
  • 2,209
  • 3
  • 23
  • 30
11

Another workaround:

Sometimes this happens to me because of network problems. I don't understand the root problem fully, but switching to a different sub-network or using VPN solves it

kip2
  • 6,473
  • 4
  • 55
  • 72
9

I had the same error. The solution was following: I've corrected my url in .git/config. Just copied that from HTTPS clone URL. That would be something like that:

url = https://github.com/*your*git*name*/*your*git*app*.git

It worked.

tan75
  • 115
  • 1
  • 2
8

Pretty straightforward solution that worked for me, see below:-

Problem
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
This should also timeout
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out
This might work
$ ssh -T -p 443 git@ssh.github.com
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
Override SSH settings
$ vim ~/.ssh/config

# You can also manually open the file and copy/paste the section below
# Add section below to it
Host github.com
  Hostname ssh.github.com
  Port 443
Then try again
$ ssh -T git@github.com
Hi xxxxx! You've successfully authenticated, but GitHub does not
provide shell access.
Try cloning now (should work)
$ git clone git@github.com:xxxxxx/xxxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 15 (delta 0), reused 15 (delta 0), pack-reused 0
Receiving objects: 100% (15/15), 22.90 KiB | 4.58 MiB/s, done.

Reference: here => Use HTTPS with Port 443

Shuvo Amin
  • 631
  • 8
  • 14
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31187769) – aaossa Mar 06 '22 at 03:49
  • This did help me. It suddenly stopped working and this was the way to fix it. – hugronaphor Mar 17 '22 at 18:19
7

After doing some research I've finally got solution for this, you have declared a environment variable to plink.exe path. So if you remove that path, reopen the git bash and try cloning through SSH it will work.

Refer to this link

http://sourceforge.net/p/forge/site-support/2959/#204c

Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
7

If after"git push origin master" command u see the error "could not read from remote repository" then try this out

1.ssh-keygen -t rsa -b 4096 -C "youremail"
2.eval $(ssh-agent -s)
3.ssh-add ~/.ssh/id_rsa
4.clip < ~/.ssh/id_rsa.pub(it copies the ssh key that has got generated)
5.then go to your remote repository on github and goto settings-> SSH and GPG keys ->new SSH key ->enter any title and paste the copied SSH key and save it
6. now give git push origin master 
Vega
  • 27,856
  • 27
  • 95
  • 103
sushmitha
  • 79
  • 1
  • 2
4

In your .git/config file

[remote "YOUR_APP_NAME"]
    url = git@heroku.com:YOUR_APP_NAME.git
    fetch = +refs/heads/*:refs/remotes/YOUR_APP_NAME/*

And simply

git push YOUR_APP_NAME master:master 
4

I had a perfectly fine working git and suddenly I got that error when I tried to push to the master. As I found out, it was because the repository host had problems.

If you using GitHub or Bitbucket you can easily check the status at

https://status.github.com/messages or https://status.bitbucket.org/

enter image description here

Adam
  • 25,960
  • 22
  • 158
  • 247
4

If you use Gitlab than you might need to log in and accept Gitlab new terms, before you try to pull or push.

Marcelo Agimóvel
  • 1,668
  • 2
  • 20
  • 25
4

I have tried everything including generating new key, adding to the GitHub account, editing .ssh/config and .git/config. But still it was giving me the same error. Then I tried following command and it does work successfully.

ssh-agent bash -c 'ssh-add ~/.ssh/id_rsa; git clone git@github.com:username/repo.git'
Chetan Pangam
  • 303
  • 3
  • 9
4

You need to use HTTPS for Git:

Type this into the Terminal:

$ git remote set-url origin abc@***.com:path/to/httpURLRepo

Then commit:

$ git add .
$ git commit -m "This is the commit message"
SwiftiSwift
  • 7,528
  • 9
  • 56
  • 96
4

updated OCT 2020

In most of the case when you have more than one user access the same git server from a same client system, that time git server confused to with access key with the user both users allowed but when you fire command that time its used default user.

ssh -T git@gitlab.com

see which user are activatly you try to push with that user

the simple solution removes the unused user public key from the git server.

then try to git fetch or pull, push it will work for me

Mr Coder
  • 507
  • 3
  • 13
3

In my case I was using an ssh key with a password to authenticate with github. I hadn't set up pageant properly in Windows (only in cygwin). The missing steps were to point the git_ssh environment variable to plink.exe. Also, you need to get github.com into the plink known_hosts.

   plink github.com
   y
   <then ctrl-c>

Hope this helps!

I sure wish intellij would have given me a more useful error, or better yet asked me to type in the ssh key password.

Jeff Hoye
  • 580
  • 5
  • 11
3
user@server:/etc/nginx$ cat .git/config 
...
[remote "origin"]
    url = git@gitlab.com:user/.git
    fetch = +refs/heads/*:refs/remotes/origin/*
...

  1. Use ssh instead of https.
  2. To use ssh key in git (add ssh key).
  3. If you are root, use the ssh key.

$ sudo ssh-keygen
$ cat /root/.ssh/id_rsa.pub 

$ git init
$ git add file
$ git commit -m "add first file"
$ git remote add origin git@gitlab.com:user/example.git 
$ git push -u origin master
Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
3

I solved this issue by restarting the terminal (open a new window/tab).

So if you don't really want/need to understand the underlying problem, test method is worth a try before digging deeper :)

mraxus
  • 1,377
  • 1
  • 15
  • 23
3

I meet the problem just now and fix it by: git config user.email "youremail".


update: The root cause maybe my poor network and poor proxy. I still don't know why it happened, but every time has this error, this command works!!!

FakeAlcohol
  • 860
  • 7
  • 28
3

In my case, The bitbucket's web ssh key setup UI is confusing.

Repository Settings -> Access keys -> Add key : Error

Personal settings -> SSH keys -> Add key : Ok

The public key registration screen is mutually exclusive. You must register the public key only in one place. It seems good to unify them on one screen.

sailfish009
  • 2,561
  • 1
  • 24
  • 31
  • This was exactly my problem, it is really strange why key that is added to the the repository didn't worked. – Macas Nov 16 '21 at 15:04
3

My issue was resolved by using these commands on Windows 11

1. I opened up the Git Bash command and started ssh-agent.

eval "$(ssh-agent -s)" // this command only work in git bash.

2. Added by ssh-key

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"  //it must be 4096
ssh-add id_rsa

3. Check properly added or not.

ssh-add -l

4. Uploaded its public key on GitHub as (Authorization key)

cat id_rsa.pub | clip

5. Unset any proxy and GIT_SSH variable

unset GIT_SSH
git config --global --unset http.proxy
git config --global --unset https.proxy

6. Must check github.com should be resolved.

ping github.com

7. Now check Connectivity with Github.

ssh -T git@github.com

Output

The authenticity of host 'github.com (20.207.73.82)' can't be established. ED25519 key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'github.com' (ED25519) to the list of known hosts. Hi MHamzaRajput! You've successfully authenticated, but GitHub does not provide shell access.

M. Hamza Rajput
  • 7,810
  • 2
  • 41
  • 36
3

I resolved this issue by change my url from

https://gitlab.com/{gitlab_user}/project_repo.git

to

https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git

using command

git remote set-url https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git
Al Fahad
  • 2,378
  • 5
  • 28
  • 37
2

For my case, I am using Corporate network (without internet connection) in office. In order to pull code from github, I set https proxy in gitbash and then use https instead of ssh to pull code,it works fine. However when comes to push code, the https proxy won't work. So either switch to Internet network (with internet connection) or set ssh proxy can solve the problem.

wenwen
  • 184
  • 1
  • 5
2

Actually I tried a lot of things to make it work on Win7, since changing the SSH exectun fron native to build-it and backwards and the same error. By chance, i change it to HTTPS in the ".git/config" file as:

[remote "origin"]
        url = https://github.com/user_name/repository_name.git
        fetch = +refs/heads/*:refs/remotes/origin/*

and it finally worked. So maybe it could work for you as well.

2

I had the same issue and after a while I saw I'm under root user (with sudo -s). May this help for someone.

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Jean-Luc Barat
  • 1,147
  • 10
  • 18
  • I confirm that even when you have set up ssh key on your machine and on the BitBucket, it will still display this error if you try to execute 'git pull' with a 'sudo' command. – ElectroBuddha Jul 19 '19 at 07:39
2

I had this problem using gitbash on windows 10. I tried several things to solve this problem, the major ones being these:

  1. Recreated my ssh keys and updated to bitbucket. Didn't help
  2. Turned on debugging using this and found out that I was getting "shell request failed on channel 0" as asked here
  3. Rebooted my windows PC

None of the above helped. I ended up re-installing Git for windows This took only a few minutes as compared to other things I did and it solved the problem!

user3885927
  • 3,363
  • 2
  • 22
  • 42
  • 1
    why I didn't see your answer 2 days ago? I already spend to much time for this fix.... :( – Max Nov 09 '21 at 23:47
2

In my case, I was trying to clone with sudo. As per Github's doc, you shouldn't use sudo with git clone: https://help.github.com/en/github/authenticating-to-github/error-permission-denied-publickey#should-the-sudo-command-be-used-with-git

What I did is give the currrent user permission to edit the directory (Debian 9):

chown myuser:root .

Then cloned without sudo and it worked.

Skoua
  • 3,373
  • 3
  • 38
  • 51
2

Not the OP' problem, but if you're working in a GitHub organization/ team, you might not have write permissions on the repository. Unfortunately, git doesn't show more specific permissions errors. In my case, I was working on a private repository, and had been given "Triage" or "Read" access.

For more information about repository access for each permission level, see GitHub documentation.

The link to change this on GitHub is https://github.com/orgs/ORGANISATION_NAME/teams/TEAM_NAME/repositories, where you can change the permissions given to the team.

Screenshot of github organisation's team's repository's tab

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167
2

I was facing the same issue. so here's the way i resolved the same

Step 1:

create a new ssh key:-

ssh-keygen -t ed25519 -C "your_email@example.com"

Step 2:

copy the ssh key on clipboard :-

pbcopy < ~/.ssh/id_ed25519.pub 

Step 3:

now paste copied ssh key to the corresponding git repository

Step 4: Start the ssh-agent in the background.

$ eval "$(ssh-agent -s)"
> Agent pid 59566

Step 5: now try accesing the repo

git clone git@github.com:username/repo-name.git

Step 6:

if still you see the issue then check the ssh config file

vim ~/.ssh/config

the content should look like

Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

Step 7:

Add your SSH private key to the ssh-agent and store your passphrase in the keychain

ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Step 8:

Now try again it should work

git clone git@github.com:username/repo-name.git
officialrahulmandal
  • 2,473
  • 1
  • 23
  • 31
1

For those having this problem on a private remote repo. make sure you have accepted the Xcode agreement on the remote server: it took we weeks to find out this fix

Use this command from the command line: sudo xcodebuild -license

1

In my case it was the postBuffer..

git config --global http.postBuffer 524288000

For reference read: https://gist.github.com/marcusoftnet/1177936

1

I had the same error, which brought me to this answer that didn't help me. I was trying to create a new "bare" repository for the first time using the commands below to track to an NTFS location:

cd myrepository
git init --bare \\myserver.mycompany.local\myrepository.git
git init
git status
git add .
git status
git commit -m "Initial Commit"
git remote add origin \\myserver.mycompany.local\myrepository.git
git push -u origin master
git status

My problem turned out to be using the back slashes instead of forward slashes in the NTFS location when trying to add origin to set the (new) tracked upstream branch.

I had to remove the origin using:

git remote rm origin

Then add the origin again using the expected forward slashes

git remote add origin //myserver.mycompany.local/myrepository.git

Hope this helps someone in the future.

Mike
  • 827
  • 11
  • 27
1

I've got this error after changing computers. I'm using SourceTree with Bitbucket.

So I had to add the SSH key generated by SourceTree, on the new computer, in Bitbucket Settings > Security > SSH keys, while connected to my Bitbucket account on the web.

eby
  • 111
  • 1
  • 4
1

I was getting this problem intermittently, where most of the time it would not give the error message. The solution for me was to configure LDAP correctly after my LDAP server's IP address had changed.

The /etc/gitlab/gitlab.rb configuration for LDAP was pointing to a non-existent IP address, and so changing the host to point to the proper hostname for the LDAP server fixed the issue.

To diagnose the issue, use the gitlab-ctl tail command to help you find stacktraces. For me, I found this stacktrace:

==> /var/log/gitlab/gitlab-rails/production.log <==

Net::LDAP::Error (No route to host - connect(2) for 10.10.10.12:389):
  /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/net-ldap-0.16.0/lib/net/ldap/connection.rb:72:in `open_connection'
...

Make the changes to the host value in /etc/gitlab/gitlab.rb

gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
   main: 
     label: 'My LDAP'
     # this was an IP address
     # host: '10.10.10.12'
     host: 'internal-ldap-server' # this is the fix
     port: 389

After changing the config file above, be sure to reconfigure gitlab

gitlab-ctl reconfigure
activedecay
  • 10,129
  • 5
  • 47
  • 71
1

It could be a Network issue.

Try doing the ssh -vvvT git@gitlab.com. If the server hangs unexpectedly it could be a dodgy network connection.

Put the following in your ~/.ssh/config

IPQoS lowdelay throughput
Joel B
  • 736
  • 7
  • 11
1

If you have set recievepack or uploadpack in my case i got the error after setting them by mistake

receivepack = powershell git receive-pack

in my case in .git/config

You can remove them as by the answer bellow

https://stackoverflow.com/a/26207308/7668448

Or by directly modifying .git/config

Mohamed Allal
  • 17,920
  • 5
  • 94
  • 97
1

Sometimes you need to use full URL with ssh:// scheme:

ssh://git@yourhost:port/path/repo.git

or with specified port:

ssh://git@yourhost:port/path/repo.git

For me it solved the problem.

Eugene Lopatkin
  • 2,351
  • 1
  • 22
  • 34
1

run into this because I am in China with Great Firewall...

kex_exchange_identification: Connection closed by remote host fatal: Could not read from remote repository.

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

paco alcacer
  • 381
  • 2
  • 13
1

In my case the problem and it's solution was written right in front of me. Earlier that day I edited the /etc/ssh/ssh_config file and added some keys. The error said:

/etc/ssh/ssh_config: line 52: Bad configuration option: allowusers
/etc/ssh/ssh_config: terminating, 1 bad configuration options
fatal: Could not read from remote repository.

I deleted the allowusers key and it's value and everything worked as expected.

Gal Shahar
  • 2,695
  • 1
  • 21
  • 29
1

I had the same issue and resolved by updating to the latest git version

Asmtony
  • 138
  • 1
  • 4
1

My solution was quite simple actually. I just had to copy and place the fingerprint from this question "Please type 'yes', 'no' or the fingerprint" instead of just hitting enter.

kenoly
  • 71
  • 1
  • 3
0

I just wanted to add to this question. I had Git setup to use PLink and Pageant for authentication and I was also getting the error FATAL ERROR: Disconnected: No supported authentication methods available (server sent: publickey). I had Pageant opened but the error was still showing up. The problem? I didn't have the private key loaded in Pageant (to add a key, follow these instructions). It was that simple.

SameOldNick
  • 2,397
  • 24
  • 33
0

When using putty/pageant, make sure you did not forget to add the correct SSH key to pageant, else this error shows up. DUH

mashup
  • 237
  • 2
  • 12
0

Go to MINGW32 terminal put this Command : git branch --set-upstream-to=origin/(branch Name)

0

If you are still getting the same error, please make sure that in the git settings->ssh tab->ssh client to use is set to openSSHenter image description here

Anil Kumar B
  • 109
  • 1
  • 4
0

According to my experience, one of the reasons this problem occured is because you have an unstable internet connection.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Marwan Salim
  • 682
  • 7
  • 14
0

I faced the same issue; simply you can run this on your command window:

git remote add origin https://your/repository/url

Jsa
  • 1
0

Adding to the "I had the same problem and...", I am also using git via Ming32 (git bash) shell in Windows.

In my case the repo requires me to type a password, not using SSH key, but it was not prompting for the password, just saying "fatal: Could not read...", although I could SSH in normally, using plink and ssh, and had set both known-host keys.

I tried most of the recommendations here and in other SOs.

I found in the end it worked fine in Powershell, but not in git bash, with no changes or corrections.

scipilot
  • 6,681
  • 1
  • 46
  • 65
0

I would recommend to check all remotes you have configured with git remote -v If you had your repo configured to a remote that was deleted you will receive this error message: fatal: Could not read from remote repository. Please make sure you have the correct access rightsand the repository exists. Even when trying to push or pull to an other (existing) remote. So if you have a remote that was deleted, you can remove with git remote remove name-of-remote-to-remove and after that you can push or pull to your existing remotes without problems.

Miguel Salas
  • 692
  • 1
  • 6
  • 21
0

I was getting this error while trying to push code to my personal git from work - defaults point to work git. So I followed these steps:

  1. Went to my personal git account and created repo with default settings
  2. On terminal, git remote add origin git@github.com:/.git
  3. git push --set-upstream origin master, ensuring that origin is upstream and the next commits can be made using git push only.

For some reason, no other way worked for me. Hope this helps someone working with 2 or more git accounts.

theusual
  • 741
  • 2
  • 11
  • 24
0

I encounter this issue by enter many times error password.

so I have to change the MaxAuthTries to a bigger number:

open the sshd_config in server end:

vim  /etc/ssh/sshd_config

change the MaxAuthTries number:

MaxAuthTries 100    # there I change to 100, you can change to a bigger than your current tries number
aircraft
  • 25,146
  • 28
  • 91
  • 166
0

In a rare case, you'll get "fatal: Could not read from remote repository" error, like in

[user@example.com repo]$ git fetch --all --prune
Fetching origin
exec request failed on channel 0
fatal: Could not read from remote repository.

when Git server filesystem is full. To verify this, please run:

ssh -v ssh://git@yourhost/path/repo.git

If the server replies like this:

...
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/...
SHA256:...
debug1: Server accepts key: /home/...
SHA256:...
Authenticated to linux-git.....com ([xxx.xxx.xx.xx]:xx) using "publickey".
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem full
...
debug1: Remote: PTY allocation disabled.
PTY allocation request failed on channel 0
shell request failed on channel 0

then the disk space on the server is exhausted.

I understand that this answer won't get many up-votes; adding it for the sake of completeness.

P.S. It is also possible to use something like

GIT_SSH_COMMAND="ssh -v" git pull

to diagnose the problem.

dmityugov
  • 4,390
  • 23
  • 18
0

To me, this occurs due to network. Your network might be slow. So change network or troubleshoot it.

navinrangar
  • 904
  • 10
  • 20
0

Had similar problem. I've added ssh key to my account by generating it via this instruction (ssh-keygen) or if you already have one add it and not generating new one. Then I changed my global credentials via command shell, they also can be changed locally for project in project root directory(remove global flag) if you already cloned repo, but it wasn`t my case. git config --global user.name "YourFirstname YourLastname" git config --global user.email "youremail@email.com"

timosh
  • 81
  • 8
0

Question has been already answered but here is another way of solving the problem https://medium.com/@deshpasheeto_sisu/error-fatal-could-not-read-from-remote-repository-f987007ee997

This might work for somebody who has no luck with other options.

Tarik1322
  • 80
  • 7
-1

i just wanted to share that i found a easy fix for that:

Access denied. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

just logout from gitlab and login again. The problems should then be fixed.

nechama b
  • 15
  • 1
-1

I had the same error but if you pass the command again you will notice that you are prompted: Are you sure you want to continue connecting (yes/no)?, and by writing "yes" and then hitting enter it should be resolved.

arilebedey
  • 31
  • 7
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 23 '21 at 06:04
  • The output of the original post shows this is not happening. The ability to read is assumed here to make a question. – Peter Krebs Dec 23 '21 at 12:31
  • @PeterKrebs This particular question was prompted right before these same errors and typing "yes" resolved the problem. – arilebedey Dec 23 '21 at 17:20