Home > Software engineering >  GitHub - ERROR: Permission to denied. Please make sure you have the correct access rights and the re
GitHub - ERROR: Permission to denied. Please make sure you have the correct access rights and the re

Time:06-24

I am able to do Git clone of repo without any error. But, when I try to push any branch upstream on GitHub, I get the following error:

(base) guoling@Guo-MacBook-Pro test % git push --set-upstream origin test-branch

ERROR: Permission to guoling9419/test.git denied to myGitHubUsername.
fatal: Could not read from remote repository.

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

How can I resolve the above issue?

Here myGitHubUsername is my GitHub username.

I have set up ssh public private key pair on my laptop. And, have already added my ssh public key (id_rsa.pub) to GitHub page.

I am using macOS Monterey version 12.4.

I accidentally overwrote my ~/.ssh/config file. I have tried to remedy it by doing the following to ~/.ssh/config:

Host agent1
        User root
        HostName 198.199.92.88

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

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

I am following this dedicated GitHub page and this Stackoverflow post to debug.

When I do ssh -T [email protected], I get the output Hi myGitHubUsername! You've successfully authenticated, but GitHub does not provide shell access.

When I do ssh github, I get the output ssh: Could not resolve hostname github: nodename nor servname provided, or not known

When I do eval "$(ssh-agent -s)", I get the output Agent pid 50031.

When I do ssh-add -l -E sha256, I get the output The agent has no identities.

When I do ssh-add -l -E md5, I get the output The agent has no identities.

CodePudding user response:

The main problem here is that user myGitHubUsername does not have permission to access repository guoling9419/test.git. Nothing you do with ssh will change that fact, though things you do with ssh can change who GitHub believe you to be.

When I do ssh -T [email protected], I get the output Hi myGitHubUsername! You've successfully authenticated, but GitHub does not provide shell access.

Assuming myGitHubUsername is the correct name, you're already all set on your mac. You just need to give myGitHubUsername permission to access repository guoling9419/test.git on GitHub (presumably through the GitHub web interface, or perhaps through their gh cli), or change the URL to point to whatever repository you're supposed to be using instead of guoling9419/test.git, using git remote set-url origin new-url for instance.

The remainder of this is optional reading

I am using macOS Monterey version 12.4.

When I do eval "$(ssh-agent -s)" ...

Don't do that on macOS: modern macOS sets up a user agent for you at the time you log in on your laptop (or whatever hardware) so that there's one already provided.

(It's not technically harmful to start a new one like this, but that disables some useful features.)

When I do ssh-add -l ...

Note that -l merely lists the currently-added identities. If you need to add some identities, use ssh-add without -l. See the documentation for details.

  • Related