Git’s famous “ERROR: Permission to .git denied to user”

gitgithubssh

I have tried googling and read through https://help.github.com/en/articles/connecting-to-github-with-ssh and various, various guides. I am unable to git push -u origin master or git push origin master ( the same command ).

I've had my git account for at least 2 or so years. I've successfully been able to create repos and push -u origin master fine on my laptop but on this desktop I'm having issues.

Here's what I tried:

1. I have setup my git user name

2. I have setup my git user email

3. I have uploaded the contents of my /home/meder/.ssh/id_rsa.pub to github's account page. I have verified I did not paste any whitespace

4. I have created a ~/.ssh/config with these contents:

  Host github.com
  User git
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa

I have chmodded the .ssh to 700, id_rsa 600

5. I have added the proper remote origin without making typos : git remote add origin git@github.com:medero/cho.git

6. To confirm #5, here is my .git/config. The directory is correct and not another directory:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:medero/cho.git

7. ssh git@github.com -v gives me a successful Authentication

8. One weird thing is, the username which it greets me with has t appended to it. My github username is medero, not medert.

Hi mederot! You've successfully
authenticated, but GitHub does not
provide shell access.

9. I am not behind a proxy or firewall

10. The key is offered, heres the output from -v:

debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/meder/.ssh/known_hosts:58
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/meder/.ssh/id_rsa
debug1: Remote: Forced command: gerve mederot
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: { some stuff, dont know if i should share it

debug1: Remote: Forced command: gerve mederot
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).

11. Here are the commands I used

mkdir cho
git init
touch README
git add README
git commit -m 'test'
git remote add origin git@github.com:medero/cho.git
git push -u origin master

12. I don't want to create a new SSH key.

13. If I git clone using ssh and make an edit, commit, and git push, I get the same exact thing.

14. Here's the actual error:

$ git push
ERROR: Permission to medero/cho.git denied to mederot.
fatal: The remote end hung up unexpectedly

15. I have setup my github username and github token:

$ git config –global github.user medero
$ git config –global github.token 0123456789yourf0123456789tokenSets the GitHub token for all git instances on the system

16. I have confirmed my github username is NOT mederot and my github token IS CORRECT per my account page ( validated first 2 chars and last 2 chars ).

17. To confirm #16, ~/.gitconfig contains

[github]
    token = mytoken...
    user = medero

18. I did ssh-key add ~/.ssh/id_rsa if that's even necessary…

THEORIES:

I suspect there's something fishy because when I get ssh authenticated, the user greeting is mederot and not medero, which is my acct. Could something in my github account possibly be incorrectly cached?

I also suspect some local ssh caching weirdness because if i mv ~/.ssh/id_rsa KAKA and mv ~/.ssh/id_rsa.pub POOPOO, and do ssh git@github.com -v, it still Authenticates me and says it serves my /home/meder/.ssh/id_rsa when I renamed it?! It has to be cached?!

Best Answer

After Googling for few days, I found this is the only question similar to my situation.

However, I just solved the problem! So I am putting my answer here to help anyone else searching for this issue.

Here is what I did:

  1. Open "Keychain Access.app" (You can find it in Spotlight or LaunchPad)

  2. Select "All items" in Category

  3. Search "git"

  4. Delete every old & strange item

  5. Try to Push again and it just WORKED