Git's famous "ERROR: Permission to .git denied to user"
Asked Answered
D

20

177

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 [email protected]: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 = [email protected]:medero/cho.git

7. ssh [email protected] -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 [email protected]: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 [email protected] -v, it still Authenticates me and says it serves my /home/meder/.ssh/id_rsa when I renamed it?! It has to be cached?!

Durware answered 17/3, 2011 at 5:22 Comment(2)
I am using "Github for Windows" and had similar issue when switched between two Github accounts. Here's my solution: #18566376Consolidation
If you are looking to push from 2 different local repos to their corresponding origin remote repo then check this: https://mcmap.net/q/56171/-how-can-i-push-to-multiple-github-accounts-from-my-pc-using-git-different-repositories/12033855Quake
O
43

In step 18, I assume you mean ssh-add ~/.ssh/id_rsa? If so, that explains this:

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 [email protected] -v, it still Authenticates me and says it serves my /home/meder/.ssh/id_rsa when I renamed it?! It has to be cached?!

... since the ssh-agent is caching your key.

If you look on GitHub, there is a mederot account. Are you sure that this is nothing to do with you? GitHub shouldn't allow the same SSH public key to be added to two accounts, since when you are using the [email protected]:... URLs it's identifying the user based on the SSH key. (That this shouldn't be allowed is confirmed here.)

So, I suspect (in decreasing order of likelihood) that one of the following is the case:

  1. You created the mederot account previously and added your SSH key to it.
  2. Someone else has obtained a copy of your public key and added it to the mederot GitHub account.
  3. There's a horrible bug in GitHub.

If 1 isn't the case then I would report this to GitHub, so they can check about 2 or 3.

More :

ssh-add -l check if there is more than one identify exists if yes, remove it by ssh-add -d "that key file"

Outsider answered 17/3, 2011 at 6:19 Comment(10)
This was it. You saved me a huge headache. Now I just have to remember to run ssh-add ... every time I want to switch my github/ssh logins.Syllabub
For some reason ssh-add -d <keyfile> doesn't work. (Manually deleting tyhe files did.) The caching you mentioned must be manually reloaded somehow. How?Rarely
ssh-add -d -> "Could not open a connection to your authentication agent."Ayacucho
The ssh-add was the bit that did it for me. Thanks!Delmardelmer
In Ubuntu, I first need to remove Secure Shell/OpenSSH keys in Passwords and Keys. That also deletes the key in ~/.ssh... so may be some backup needed. Then ssh-add <key> and ssh-add -d work as expected.Fireweed
ssh-add finally made it!Munch
ssh-add -d solved for meFled
I had the same issue. I was using two 2 separate GitHub accounts at the same time and git was detecting the previous one. I had to run eval comman i.e., eval $(ssh--agent -s) and then run add command i.e., ssh-add ~/.ssh/<THE_SSH_KEY>Printer
@Ayacucho I also got the could not open connection to authentication agent, but running the eval and ssh-add suggested by @Printer fixed the Github issue AND the authentication agentStillhunt
@Ayacucho I found that this is not persistent. After rebooting I had to do eval $(ssh-agent -s) etc. again. I looked at the manpage for ssh-agent and it said there are two common ways ssh-agent is started and both rely on X. Since I'm using Wayland (and possibly you too?) this doesn't happen, so I've put it in my .bashrc instead :)Stillhunt
R
198

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

Regimen answered 23/6, 2015 at 14:7 Comment(10)
Glad I decided to google this instead of following the lack of detail on github's support pageSverre
Thanks,I ended up here and removing SourceTree account.Ailsun
Hell yes, finally, after struggling with countless SSH keys, this is the answer that worked! Seems that Mac and https access uses the Keychain. Crazy.Clerkly
Looks very helpful, but unclear what is old & strange. Am I about to mess a load of stuff up..?Escamilla
Step 4 for me was just changing the user and password at github.com.Underpinnings
this is really working well. I will share this answer in my blog post later.Lampert
I was so stuck with the accepted answer above until I read yours.Chilopod
@Escamilla The old & strange things means the old date items and incorrect email or username. You can sort the table by Date Modified.Regimen
This also fixes an issue with SoureTree, where the app uses old user names to commit changesKryska
great solution, but i faced an annoying bug which is if you searched for git in keychain you won't be able to delete !!! here the solution : apple.stackexchange.com/a/344380/433379Forint
T
142

If problem is coming on windows then remove the Credentials from the Windows history.

  • Go to Credential Manager
  • Go to Windows Credentials
  • Delete the entries under Generic Credentials
  • Try connecting again.This time , it should prompt you for the correct username and password.

enter image description here enter image description here

remove credentials from git

Twain answered 1/12, 2016 at 9:38 Comment(5)
Perfect. I was getting 403 accessing with an account that I don't use anymore. Now solved.Cowpoke
only deleting the github.com credentials was sufficient for meVirtuosity
And there you can change your username and anything. That is the way.Airsickness
Actually this worked for me as well but what would I do if I had 2 different accounts?Quake
this action solved my issue in windowsIolanthe
O
53

On Mac, if you have multiple GitHub logins and are not using SSH, force the correct login by using:

git remote set-url origin https://[email protected]/username/repo-name.git

This also works if you're having issues pushing to a private repository.

Odonnell answered 12/11, 2017 at 4:39 Comment(7)
Thanks, this worked for me. It prompted me for password and I was able to push after I provided my password. Much appreciated!Begley
... but this did not solve issue for me on Windows, only on MacBegley
... but @Fahid suggeston above to clean up credentials on Windows helpedBegley
This is the correct answer if we multiple github projects which belongs to different accountsFasten
This worked. Previously my url was set to the https one. When I changed to [email protected]:organization/reponame.git git push workedRickety
this route looks like it may no longer be supported: remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.Lundin
Still works if you have a token, @Lundin - just enter the token text when asked for a password. See Creating a personal access token for instructions. And, this SO question explains the minimum scopes needed to set up the token for push activities.Odonnell
O
43

In step 18, I assume you mean ssh-add ~/.ssh/id_rsa? If so, that explains this:

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 [email protected] -v, it still Authenticates me and says it serves my /home/meder/.ssh/id_rsa when I renamed it?! It has to be cached?!

... since the ssh-agent is caching your key.

If you look on GitHub, there is a mederot account. Are you sure that this is nothing to do with you? GitHub shouldn't allow the same SSH public key to be added to two accounts, since when you are using the [email protected]:... URLs it's identifying the user based on the SSH key. (That this shouldn't be allowed is confirmed here.)

So, I suspect (in decreasing order of likelihood) that one of the following is the case:

  1. You created the mederot account previously and added your SSH key to it.
  2. Someone else has obtained a copy of your public key and added it to the mederot GitHub account.
  3. There's a horrible bug in GitHub.

If 1 isn't the case then I would report this to GitHub, so they can check about 2 or 3.

More :

ssh-add -l check if there is more than one identify exists if yes, remove it by ssh-add -d "that key file"

Outsider answered 17/3, 2011 at 6:19 Comment(10)
This was it. You saved me a huge headache. Now I just have to remember to run ssh-add ... every time I want to switch my github/ssh logins.Syllabub
For some reason ssh-add -d <keyfile> doesn't work. (Manually deleting tyhe files did.) The caching you mentioned must be manually reloaded somehow. How?Rarely
ssh-add -d -> "Could not open a connection to your authentication agent."Ayacucho
The ssh-add was the bit that did it for me. Thanks!Delmardelmer
In Ubuntu, I first need to remove Secure Shell/OpenSSH keys in Passwords and Keys. That also deletes the key in ~/.ssh... so may be some backup needed. Then ssh-add <key> and ssh-add -d work as expected.Fireweed
ssh-add finally made it!Munch
ssh-add -d solved for meFled
I had the same issue. I was using two 2 separate GitHub accounts at the same time and git was detecting the previous one. I had to run eval comman i.e., eval $(ssh--agent -s) and then run add command i.e., ssh-add ~/.ssh/<THE_SSH_KEY>Printer
@Ayacucho I also got the could not open connection to authentication agent, but running the eval and ssh-add suggested by @Printer fixed the Github issue AND the authentication agentStillhunt
@Ayacucho I found that this is not persistent. After rebooting I had to do eval $(ssh-agent -s) etc. again. I looked at the manpage for ssh-agent and it said there are two common ways ssh-agent is started and both rely on X. Since I'm using Wayland (and possibly you too?) this doesn't happen, so I've put it in my .bashrc instead :)Stillhunt
L
39

Its due to a conflict.

Clear all keys from ssh-agent

ssh-add -d ~/.ssh/id_rsa
ssh-add -d ~/.ssh/github

Add the github ssh key

ssh-add   ~/.ssh/github

It should work now.

Lie answered 11/11, 2011 at 19:48 Comment(4)
also ssh-add -D removes all identities, can be useful if the agent gets into an invalid state.Voluntaryism
ssh-add finally made it!Munch
11 years old answer but still useful :DColombo
Keychain cleaning didn't help, this one solved my problem!Shrift
Z
7

I am using Mac and the issue is solved by deleting github record from keychain access app: Here is what i did:

  1. Open "Keychain Access.app" (You can find it in Spotlight orLaunchPad)
  2. Select "All items" in Category
  3. Search "git"
  4. Delete every old & strange items Try to Push again and it just WORKED

Above steps are copied from @spyar for the ease.

Zachary answered 15/2, 2017 at 14:36 Comment(0)
F
7

I find the solution is the same as @spyar provide which is the Keychain Access app stored the old username.

There are 2 solutions for this situation:

  1. Delete the info in Keychain Access by
    • Open Keychain Access app
    • Search for GitHub
    • Delete corresponding credentials

Or

  1. If you want to use ssh key. You just change your Repo url from https

    https://github.com/username/repo.git

    into

    [email protected]:username/repo.git

Flibbertigibbet answered 19/2, 2017 at 4:43 Comment(0)
F
4

I recently ran into this issue for on old repo on my machine that had been pushed up using https. steps 5 and 6 solved my issue by re-setting the remote url for my repo from using the https url to the ssh url

checking the remote is using the https url

> git remote -v
origin  https://github.com/ExampleUser/ExampleRepo.git (fetch)
origin  https://github.com/ExampleUser/ExampleRepo.git (push)

then re-setting the origin to use the ssh url

> git remote set-url origin [email protected]:ExampleUser/ExampleRepo.git

verifying new remote

> git remote -v
origin  [email protected]:ExampleUser/ExampleRepo.git (fetch)
origin  [email protected]:ExampleUser/ExampleRepo.git (push)

could now successfully git push -u origin

i'm still not sure what setting i would have changed that might have caused the push to fail when the remote is https but this was the solution to my issue

Fitch answered 22/1, 2019 at 19:23 Comment(1)
ERROR: Permission to unrealcv/synthetic-computer-vision.git denied to monajalal. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.Turn
E
4

I was running into similar issue on Mac OS.

Summary

  1. Make sure the repo gets cloned with correct/intended username
  2. If you try to clone a repo without specifying GitHub username, it picks up the GitHub username already cached in the OSX's Keychain Access utility
  3. Hence I had to specify username while cloning the repo - git clone https://[email protected]/username/repository.git
  4. When it prompts to enter password, you may have to use a use a personal access token (PAT) because support for password authentication was removed on August 13, 2021 by GitHub. Here's some documentation around personal access tokens (PAT) and how to set up and use
  5. The initial push might also require specifying username git push https://[email protected]/username/repository.git and providing PAT as password
  6. On subsequent pushes, no password would be prompted as they get cached to OSX Keychain Access util. Also, I didn't have to use the full URL to push. Just git push <origin/remote/upstream> <branch> worked fine

More details about my set up/situation/issue

Essentially I was trying to work with two different GitHub (github.com) accounts (1. Work account/email & 2. Personal account/email)

Mine was a little peculiar case because I had an existing SSH key generated with my personal email when our organization was on premise before migrating our repos to public github.com and that key was also configured for Bastion AWS (Amazon Web Services). I couldn't regenerate a new key with the same email and also I did not generate a new key with work email which would have required to update the key configured for Bastion AWS

Note: My initial set up itself wasn't correct because at that time I didn't have much knowledge about how to work with or use SSH keys, so I realized I set them up incorrectly

Following approach worked for me (Note that this is a work around). I fell back to using GitHub Personal Access Token (PAT) instead.

git clone https://[email protected]/username/repository.git

Prompted password, I entered my PAT here (which then got cached to OSX Keychain Access)

And then

git push https://[email protected]/username/repository.git

On my subsequent pushes, no password prompts and I didn't have to use the full URL to push. Just git push <origin/remote/upstream> <branch> worked fine

Elizaelizabet answered 17/7, 2022 at 13:5 Comment(0)
C
2

Same issue was observed when pushing to a respository:

$ git push --set-upstream origin new-operator-test
ERROR: Permission to redhat-openshift-ecosystem/redhat-marketplace-operators.git denied to cniackz.
fatal: Could not read from remote repository.

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

What was done is making sure you clone your forked repository:

git clone [email protected]:cniackz/redhat-marketplace-operators.git
git checkout -b new-branch
<performed the changes>
git add <files>
git commit -m <files>

And it worked:

$ git push --set-upstream origin new-branch
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 10 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (7/7), 643 bytes | 643.00 KiB/s, done.
Total 7 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: 
remote: Create a pull request for 'new-branch' on GitHub by visiting:
remote:      https://github.com/cniackz/redhat-marketplace-operators/pull/new/new-branch
remote: 
To github.com:cniackz/redhat-marketplace-operators.git
 * [new branch]      new-branch -> new-branch
Branch 'new-branch' set up to track remote branch 'new-branch' from 'origin'.

It is suspected that to start with, it was not used the forked repository but the one from redhat and this would explain the issue since cniackz user does not have access to that repository but to forked only.

Coadjutress answered 17/3, 2011 at 5:23 Comment(0)
H
2

I had the same problem as you. After a long time spent Googling, I found out my error was caused by multiple users that had added the same key in their accounts.

So, here is my solution: delete the wrong-user's ssh-key (I can do it because the wrong-user is also my account). If the wrong-user isn't your account, you may need to change your ssh-key, but I don't think this gonna happen.

And I think your problem may be caused by a mistyping error in your accounts name.

Hesione answered 31/5, 2013 at 2:27 Comment(1)
This is the same issue on my side. After deleting wrong-user's ssh-key, if it is still not working, then do: ``` 1. go back to your "correct" account, remove and re-add your ssh key again 2. close your terminal and reopen your terminal, then push your code ```Dentition
E
2

I encountered this error when using Travis CI to deploy content, which involved pushing edits to a repository.

I eventually solved the issue by updating the GitHub personal access token associated with the Travis account with the public_repo scope access permission:

Select <code>public_repo</code>

Eliseelisee answered 17/1, 2019 at 13:28 Comment(0)
M
0

This problem is also caused by:

If you are on a mac/linux, and are using 'ControlMaster' in your ~/.ssh/config, there may be some ssh control master processes running.

To find them, run:

ps aux | grep '\[mux\]'

And kill the relevant ones.

Massimo answered 23/7, 2015 at 22:9 Comment(0)
C
0

I too ran into this, what caused this for me is that while cloning the repo I was pushing my changes to, I picked up the clone URL from an incognito tab without signing in. (I am still clueless on how it effects). That for some reason led to git picking another user account. When i tried it again from a proper signed in page it worked like usual for me.

Chrysanthemum answered 27/1, 2018 at 6:42 Comment(0)
T
0

I also happen to come across this issue while working on my MAC So, the problem is this. I had once logged in from one of my old GitHub account. Now, I am using a different GitHub account. I solved using the below steps-

  1. Open "Keychain Access.app"
  2. Select "All items" in Category
  3. Search "Github"
  4. Open that entry,
  5. and change the Account to new github username.

Try to Push again and it will work

Triplicity answered 7/5, 2021 at 8:32 Comment(0)
B
0

Steps that help me:

  1. Deleted all the existing PATs on github and created a new one.
  2. Make sure to check the     repo     section when creating a new PAT. Following is image from github as example: step 8 of the above link
    For me this step was the source for the error, since I followed the above step 1 correctly.
  3. Update you github password in your local machine windows or mac

That's all I think.

Bearce answered 22/7, 2022 at 12:45 Comment(0)
O
0

I ran into this issue when trying to clone a private repository from an organization. In my case the solution was to delete the SSH key from GitHub and add a new one.

Outlaw answered 7/12, 2022 at 9:19 Comment(0)
G
0

In my case, I simply wasn't added to the organization whose repository I want to contribute to, everything else was set up. So I asked the organisation owner to add me, and it worked.

Greco answered 15/6, 2023 at 16:3 Comment(0)
G
0

ERROR SEARCH PURPOSES:

error: remote: Permission to USERNAME-1/REPONAME.git denied to USERNAME-2. fatal: unable to access 'https://github.com/USERNAME-1/repo.git/': The requested URL returned error: 403

error: failed to push some refs to 'https://github.com/user/repo.git

error: you dont have permission to push to "repo" on github. would you like to create a fork and push to it instead

I had this error ^. so i followed this and it worked for me.

my solution:

i deleted all .git or git credentials. nothing else.

hope this helps a fellow wanderer.

Gpo answered 5/9, 2023 at 10:31 Comment(0)
D
0

In my case, I had two different ssh key for two account. One was for work and one was for personal github account. I resolved it by changing the .ssh/config file and git remote url.

At first my .ssh/config file was like below:

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

And my git remote url was [email protected]:myusername/my-repo-name.git

Then first I changed the .ssh/config file with adding two hosts like following:

#Github Work Account
Host git_work
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ssh_work

#Github Personal account
Host git_personal
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ssh_personal

#General
Host *
    UseKeychain yes
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_ssh_work

And git remote url to git_personal:myusername/my-repo-name.git by replacing "[email protected]" with "git_personal" the hostname that I gave in config file.

But still it was not work then I just remove the "Host *" related portion from the .ssh/config the it worked. So at last my .ssh/config was like below:

#Github Work Account
Host git_work
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ssh_work

#Github Personal account
Host git_personal
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_ssh_personal

Then finally the error was gone and it worked. Hopefully someone may benefit from it if there case is similar like me.

Damnation answered 8/1 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.