Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github remote permission denied

Tags:

git

github

I'm trying to upload my repo on github and go through all the steps upto:

git push -u origin master

at that point it gives me the following error:

remote: Permission to samrao2/manager-4.git denied to samrao1.

fatal: unable to access 'https://github.com/samrao2/manager-4.git/': The requested URL returned error: 403

I think the issue is that i was logged into another Git account before "samrao1" and now i am trying to push to "samrao2".

Can someone help me reset this to where i can successfully push to "samrao2". I am assuming i will be prompted for my password the first time i try to do it.

like image 700
Sam Rao Avatar asked Nov 24 '17 02:11

Sam Rao


People also ask

How do I fix error permission denied Publickey fatal could not read from remote repository Github?

The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository. To solve this error, make sure your key is being used on your Git account. If it is not, add your key to Git.


2 Answers

Unable to access https means: this has nothing to do with SSH (and switching to SSH, while possible, does not explain the original issue)

This has to do with credential caching, meaning Git will be default provide the credentials (GitHub account and password PAT Personal Access Token) of the old account while you are trying to push to the new account.


Reminder, most Git repository hosting service uses token as password, not your actual user account password.
For instance, GitHub no longer accept password since Aug. 2021.


See if you have a credential helper that would have cached your (old account) credentials (username/password) used to authentication you.

git config credential.helper  

On Mac, as commented by Arpit J, just goto/open your keychain access->search for github.com related file->and edit credentials there.

https://help.github.com/assets/images/help/setup/keychain-access.png

See "Updating credentials from the OSX Keychain"

On Windows (And, in 2021, possibly Linux or even Mac), that would be the Windows Credential Managers GCMC: Git Credential Manager.
Open the Windows Credential Store, and see if the first user is registered there: delete that entry, and you will be able to authenticate with the second user.

(Here is an example for BitBucket)

https://kwilson.io/blog/wp-content/uploads/2015/01/4-store.png


In command-line (see git credential), for a manager core credential helper:

  • Get the old password or token:

    printf "protocol=https\nhost=github.com\nusername=<me>" | \   git credential-manager-core get  # output: protocol=https host=github.com username=<me> password=<old_password_or_token> 
  • Remove the old password:

    printf "protocol=https\nhost=github.com\nusername=<me>" | \   git credential-manager-core erase 

(Replace <me> by your GitHub user account name)

like image 111
VonC Avatar answered Sep 17 '22 17:09

VonC


If you are using MacOS, you can

  1. go to KeyChain Access,
  2. Search for "GitHub",
  3. then when then result "github.com" pops up, change the account or password to your new account, and save.

Then you are all set!

like image 40
Novus Avatar answered Sep 19 '22 17:09

Novus