115

I am getting this error -

D:\Projects\wamp\www\REPO [master]> git pull origin master
Warning: Permanently added 'github.com,192.30.252.128' (RSA) to the list of known hosts.
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

The output of git remote -v

D:\Projects\wamp\www\REPO [master]> git remote -v
origin  git@github.com:username/repo.git (fetch)
origin  git@github.com:username/repo.git (push)

Final message of ssh -Tv git@github.com command -

Hi [My Username]! You've successfully authenticated, but GitHub does not provide shell access.

How can I solve it?

Nisarg
  • 3,024
  • 5
  • 32
  • 54
  • 2
    You should verify that you can still `git clone` against the repo. If you cannot even clone then you need to check your authentication tokens. – merlin2011 May 06 '15 at 05:40
  • 5
    Does `ssh -Tv git@github.com` work? – VonC May 06 '15 at 05:41
  • Check your github ssh keys. – uraimo May 06 '15 at 05:42
  • Do you actually have username/repo.git as your branches, or your actual username and repo name? – Steve Chaloner May 06 '15 at 05:46
  • Then try to fix that first: make sure HOME is defined (it is not by default on Windows): https://help.github.com/articles/generating-ssh-keys/#platform-windows – VonC May 06 '15 at 05:46
  • @Napster so it does work? You said "no not work" before. – VonC May 06 '15 at 05:47
  • @VonC : I mean It not solved my problem. What now ? – Nisarg May 06 '15 at 05:50
  • @Napster check the case (lowercase/uppercase) of your username and repo on GitHub: the url must use the exact username and reponame. – VonC May 06 '15 at 05:52
  • @VonC : I am working on this repo for more then 5 month. Suddenly it stopped to work. Username and repo letter case is also right. I had just changed my profile pic. Is this can be a problem ? I don't know because I am new for github. I know only basic use of git. – Nisarg May 06 '15 at 05:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77061/discussion-between-napster-and-vonc). – Nisarg May 06 '15 at 05:57
  • @Napster does `ssh -T git@github.com` ouput the same username (in `Hi [My Username]!`) as in the one used for the ssh url of your repo (`git@github.com:username/repo.git`)? What version of Git are you using on Windows? – VonC May 06 '15 at 05:59
  • thanks @VonC after i ran that command, i was then able to run "git push". not sure how that debugging worked. maybe it just took some time for github to register my new repo. – Randy Tang Jun 03 '23 at 18:27
  • @RandyTang May be: as long as you are correctly authenticated, the push (to *your* repository) should succeed. – VonC Jun 03 '23 at 18:35

23 Answers23

115

change your ssh url by an http url for your remote 'origin', use:

> git remote set-url origin https://github.com/<user_name>/<repo_name>.git

It will ask for your GitHub password on the git push.

Siyaram Malav
  • 4,414
  • 2
  • 31
  • 31
  • 12
    I just tried that, it gave me an error: `fatal: No such remote 'origin'` – Rich Dec 06 '16 at 06:44
  • 1
    I don't know what it does but it worked and I can get on with my life! Thanks – Kostas Demiris Jul 14 '17 at 07:54
  • 3
    `origin` is the remote name. If you called your remote something else than origin, this will not work just by copy-pasting. Replace `origin` with your remote name – Zoe Jul 28 '17 at 16:23
  • I had the same problem and this solution worked for me, while other solutions did not work for me. Thanks! – Norbert S Mar 04 '18 at 04:20
  • Now, everytime when I want to push, git wants a username and password. how do I fix it? – max Mar 25 '21 at 12:57
  • 6
    BTW as of August 13, 2021 this solution will not work as Github as deprecated the use of passwords in all authenticated operations – StonedTensor Sep 01 '21 at 22:08
  • When I try this I get: `fatal: not a git repository (or any of the parent directories): .git` – mikey Oct 15 '21 at 11:42
  • 1
    Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. – Ehsan Nov 03 '21 at 18:52
  • In my case, ssh agent was still using the saved private key of another Github user, so I got the same error regardless of ssh or https. It only worked after I use "ssh-agent" to add the private key of the user with access to the repo. This could be seen with "ssh -Tv git@github.com" command. – David Ha Aug 01 '23 at 01:56
32

I asked in the discussion:

does ssh -T git@github.com ouput the same username (in Hi [My Username]!) as in the one used for the ssh url of your repo (git@github.com:username/repo.git)?

Sorry It not showing same name

That means somehow the credentials have changed.

One solution would be to at least copy %HOME%\.ssh\id_rsa.pub in the SSH keys section of the right GitHub account

The OP adds:

I am working on private repo. So In git@github.com:username/repo.git,

I replied:

If you were able to clone/push to that repo whose username is not your own GitHub account, that must be because you had your previous public ssh key added as a contributor to that repo by the repo's owner.

What next is to ask that same repo owner to add your current public ssh key %HOME%\.ssh\id_rsa.pub to the repo contributor list.
So check with the owner that you (meaning your public ssh key) are declared as a contributor.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
28

For me, I was getting this error because my ssh agent was not running somehow. Doing this worked:

eval `ssh-agent -s`
ssh-add path_to_your_key
Shashank Ks
  • 450
  • 5
  • 9
16

Sometimes that (copying the pub ssh key to github/bitbucket) is not enough, particularly with Bitbucket. You also may need to check if your ssh is using the identity you expect rather than messing up with git remote

Check if the agent is using the same identity you pasted on github/bitbucket with ssh-add -l. If missing add it with

ssh-add ~/.ssh/id_rsa_my_git_identity

Further details: https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html

Jaime Agudo
  • 8,076
  • 4
  • 30
  • 35
  • 1
    I followed your suggestion by adding the identity and all steps listed in above url, i still have issues in git push; i have no issues in git clone or git fetch or git pull; when i do git push origin master, it says ```Unauthorized fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.``` – soMuchToLearnAndShare Dec 06 '22 at 01:30
  • 1
    below helped: https://stackoverflow.com/questions/56828685/cant-git-push-to-bitbucket-unauthorized-fatal-could-not-read-from-remote-re?rq=1 – soMuchToLearnAndShare Dec 06 '22 at 01:35
11

This error happened to me too as the original repository creator had left the company, which meant their account was deleted from the github team.

git remote set-url origin https://github.com/<user_name>/<repo_name>.git

And then git pull origin develop or whatever git command you wanted to execute should prompt you for a login and continue as normal.

Muhan Alim
  • 479
  • 1
  • 7
  • 17
  • 2
    In my case, I shared my with someone - they had to set *their* on the git path for **push** to work, **pull** worked previously because I had their SSH in the read-only SSH keys section. Confused the heck out of myself but then this finally did the trick! :D – Grant Feb 02 '22 at 01:18
9

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

kip2
  • 6,473
  • 4
  • 55
  • 72
  • This also was the case for me. I just disconnected and reconnected to my WLAN. – Guillermo May 04 '16 at 12:09
  • If I could vote more than once I would do it. actually my problem was setting a DNS somewhere and that was blocking me – MohammadHossein Jamshidi Apr 07 '23 at 12:56
  • Was searching for this, otherwise I would have wrote my own answer. I did all the steps listed given here and there. Verbose ssh did indeed show my key was succeeding in reaching my bitbucket repo, just failed with this error message the OP had. I'm on OS X Monterey and it recently gave me a security update. I correlated this issue to that. Needless to say, that was a red herring and my office Wifi was the issue. Trying any other network and it git remote ran normally. – joeljpa Apr 27 '23 at 05:26
8

This error can be because of no SSH key on the your local machine. Check the SSH key locally:

$ cat ~/.ssh/id_rsa.pub

If above command do not give any output use below command to create ssh key(Linux/Mac):

$ ssh-keygen 

Now again run cat ~/.ssh/id_rsa.pub This is your SSH key. Copy and add this key to your SSH keys in on git. In gitlab/bitbucket go to

profile settings -> SSH Keys -> add Key

and add the key

BSB
  • 2,270
  • 17
  • 26
8
ssh-add -D  # Delete all identities.
ssh-add ~/.ssh/your_key

Edit 1
Since I get so many votes, I discovered some issue with this approach and that is that it will remove all your identities so you might have the same issue when you try to read from other repositories and you will need to to this step again for each project...but it might also not be the case for your project

Tudor
  • 1,510
  • 1
  • 18
  • 17
2

I got the very same errors too. In My case upgrading from Windows 7 to 8 messed up my settings. What helped was to regenerate the private and public SSH keys using PuTTYGen, and change the SSH tool in tortoisegit from SSH to Plink.

I have shared the step by step steps also at http://techblog.saurabhkumar.com/2015/09/using-tortoisegit-on-windows-with.html

Saurabh Kumar
  • 2,329
  • 6
  • 32
  • 52
2

Maybe, as in my silly situation, you may somehow created the ssh key by directly typing

ssh-keygen

And so it is created with the local system user credentials so they don't match, use full command like this and recreate

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Erdinç Çorbacı
  • 1,187
  • 14
  • 17
2

Try:

git config --global credential.helper cache

This command prevents git to ask username and password, not forever but with a default limit to 15 minutes.

git config --global credential.helper 'cache --timeout=3600'

This moves the default limit to 1 hour.

2

For me none of the solutions here solved it. Frustrated, I restarted my Macbook's iTerm terminal, and voila! My github authorization started working again.

Weird, but maybe iTerm has its own way of handling SSH authorizations or that my terminal session wasn't authorized somehow.

Jonathan Perry
  • 2,953
  • 2
  • 44
  • 51
2

Easy solution for me:

1.) The public SSH Key has to be saved on https://github.com/settings/keys

2.) The email address inside "~/.ssh/id_rsa.pub" (At the end of the file) has to be entered on Github (https://github.com/settings/emails). (This was my problem)

After I saved the email address on GitHub, the problem solved itself.

emovere
  • 152
  • 1
  • 13
1

I had this issue and tried many things but still din't work. Eventually I decided to generate another SSH KEY and boom - it worked. Follow this article by github to guide you on how to generate your SSH KEY.

Lastly don't forget to add it to your github settings. Click here for a guide on how to add your SSH KEY to your github account.

otoloye
  • 677
  • 7
  • 11
1

In my case updating GIT helps - I had version 2.23 and with installing version 2.26.2.windows.1 problem disapears.

So if you are sure your SSH key is valid then (see @VonC answer):

  1. update GIT
  2. update composer
  3. run composer clearcache

And it should be ok.

Manic Depression
  • 1,000
  • 2
  • 16
  • 34
0

This issue could be related with missing SSH key at Github or any other git server.

In my case I had copied code to another computer and tried to git pull. It failed.

So I had to generate a new SSH key on that machine and update profile on git server with additional SSH key.

laimison
  • 1,409
  • 3
  • 17
  • 39
0

Strangely I had this occur with a single repository out of > 20 repositories on my MacBook Pro.

The solution was to upgrade git via homebrew, and everything strangely worked after it finished:

brew install git

Hope this helps someone!

Steve Bauman
  • 8,165
  • 7
  • 40
  • 56
0

Its not necessary to apply above solutions, I simply changed my internet, it was working fine with my home internet but after 3 to 4 hours my friend suggest me to connect with different internet then I did data package and connect my laptop with it, now it is working fine.

nafees ahmed
  • 948
  • 1
  • 12
  • 18
0

I had the same problem. I tried a couple of solutions mentioned above, it did not work for me. I even restarted my machine and also reconnected my WLAN. But all in vain. Then on the remote repo, I manually made a small change in the readme file of the repo. To pull that change on the local copy of my repo in my machine, I did the usual git pull and then the git push origin. This actually worked.

BZKN
  • 1,499
  • 2
  • 10
  • 25
0

For me somehow sudo rebooting the fluffing EC2 instance after a fresh ssh-keygen and rm ~/.ssh/known_hosts fixed it! Still not sure how it works but it worked on 4 different EC2 servers with uptime over 700 days. I think it is related to some breaking updates on some processes during the 700 days!! Still not sure what fixed it but for damn its fixed!

Nidhin David
  • 2,426
  • 3
  • 31
  • 45
0

I had this same issue and resolved it by adding my SSH key in the ~/.ssh/config file and then updating my git repo url.

~/.ssh/config:

Host github.com-repo-0
    Hostname github.com
    IdentityFile=/home/user/.ssh/repo-0_deploy_key

git repo url:

$ git remote set-url origin git@github.com-repo-1:OWNER/repo-1.git

Note that the Host text exists between the @ and : symbols in the git url.

Source: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys

Austin Heller
  • 171
  • 1
  • 9
0

same issue I have faced. 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
-2

The error message you encountered, "Permission denied (publickey)," indicates that you don't have the proper authentication set up to access the remote repository on GitHub. When using the SSH protocol (the default for GitHub), you need to have an SSH key associated with your GitHub account for secure communication and repository access.

To fix this issue and clone the repository successfully, follow these steps:

  1. Check for Existing SSH Keys: First, check if you already have an SSH key set up on your computer. Open your terminal or command prompt and run:

    ls -al ~/.ssh
    

    This command will list all files in the ~/.ssh directory. Look for files named id_rsa and id_rsa.pub, which are your private and public SSH keys, respectively.

  2. Generate a New SSH Key (If Needed): If you don't have an SSH key or need to generate a new one, use the following command:

    ssh-keygen -t rsa -b 4096 -C "your@email.com"
    

    Replace "your@email.com" with the email associated with your GitHub account. Press Enter to accept the default file location and set a passphrase (or leave it blank for no passphrase).

  3. Add the Public Key to Your GitHub Account: After generating the SSH key, you need to add the public key (id_rsa.pub) to your GitHub account. Copy the contents of the public key file using the following command:

    cat ~/.ssh/id_rsa.pub
    

    Copy the output to your clipboard.

    Then, go to your GitHub account's settings and navigate to "SSH and GPG keys." Click "New SSH key," paste the copied public key into the "Key" field, and give it a recognizable title. Finally, click "Add SSH key" to save it.

  4. Try Cloning Again: With the SSH key added to your GitHub account, try cloning the repository again using the same git clone <repository_url> command.

    git clone <repository_url>
    

    The cloning process should now work without asking for your username and password.

If you encounter any issues or still face permission problems, double-check your SSH key setup and verify that it's correctly added to your GitHub account. Additionally, make sure you're using the correct repository URL when cloning. The URL should be in the format git@github.com:username/repository.git.