简体   繁体   中英

Permission denied error on Github Push

Recently, I'm added as a member/contributor for Github project. I have cloned that project on local machine.

I have made some changes and committed locally and now trying to Push changes to original repo but when I try to Push,I get some permission error?

C:\Users\MM\Documents\GitHub\software-licensing-php [master]> git push
origin master
remote: Permission to EasySoftwareLicensing/software-licensing-php.git denied to
 irfandayan.
fatal: unable to access 'https://github.com/EasySoftwareLicensing/software-licen
sing-php.git/': The requested URL returned error: 403
C:\Users\MM\Documents\GitHub\software-licensing-php [master]> git statu
s
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

Am I lacking some permission for pushing changes so I could ask the original author of project?

  • click fork button on original github project page
  • clone your forked repository instead original
  • push to it
  • press Pull Requests button on your repository
  • create it
  • wait for original author to accept it

I used to have the same error when i change my user email by git config --global user.email and found my solution here: Go to: Control Panel -> User Accounts -> Manage your credentials -> Windows Credentials

Under Generic Credentials there are some credentials related to Github, Click on them and click " Remove ".

and when you try to push something, you need to login again. hope this will be helpful for you

In could able to resolve this issue with giving username and password in below url.

Please replace username and password with your Github credentials:

git remote set-url origin https://<username>:<password>@github.com/<username>/FirstRepository.git

For some reason my push and pull origin was changed to HTTPS-url in stead of SSH-url (probably a copy-paste error on my end), but trying to push would give me the following error after trying to login:

Username for 'https://github.com': xxx
Password for 'https://xxx@github.com': 
remote: Invalid username or password.

Updating the remote origin with the SSH url, solved the problem:

git remote set-url origin git@github.com:<username>/<repo>.git

Hope this helps!

See the github help on cloning URL . With HTTPS, if you are not authorized to push, you would basically have a read-only access. So yes, you need to ask the author to give you permission.

If the author doesn't give you permission, you can always fork (clone) his repository and work on your own. Once you made a nice and tested feature, you can then send a pull request to the original author.

Another way to get this error, is if you have duplicate or conflicting ~/.ssh/* entries. First check what is on your ssh key-chain with:

$ ssh-add -l
2048 SHA256:<hash1> email2@gmail.com (RSA)
2048 SHA256:<hash2> email1@gmail.com (RSA)
2048 SHA256:<hash3> email1@gmail.com (RSA)

As you can see there are two emails which are the same, and easy for you to get confused. Then check your config file:

$ cat ~/.ssh/config

# GitHub: email1@gmail.com
Host github_ex
 HostName github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/github_ex

# GitHub: email2@gmail.com
Host github
 HostName github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/github

# Bitbucket: email1@gmail.com
Host bitbucket
 HostName bitbucket.org
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/bitbuc

Here you see that you have two different email accounts to github but same HostName . Someone is bound to get confused, including your git.

To resolve, manually remove (after copying) the (default) files:

cd ~/.ssh
rm id_rsa
rm id_rsa.pub

Now copy back the one you want to use, for example Host github :

cp -a github id_rsa
cp -a github.pub id_rsa.pub

Then try again.

For some reason, removing keys with ssh-add -d id_rsa didn't work as expected, as it seem that key-chain is cached.

I had this problem too but managed to solve it, the error is that ur computer has saved a git username and password so if you shift to another account the error 403 will appear. Below is the solution For Windows you can find the keys here:

control panel > user accounts > credential manager > Windows credentials > Generic credentials

Next remove the Github keys.

Based on the information that the original poster has provided so far, it might be the case that the project owners of EasySoftwareLicensing/software-licensing-php will only accept pull requests from forks, so you may need to fork the main repo and push to your fork, then make pull requests from it to the main repo.

See the following GitHub help articles for instructions:

  1. Fork a Repo .
  2. Collaborating .

one final answer (the others no doubt really answered it): it may also be, you are running a really old git version. upgrade to a newer git that gives you the proper options (use of PAT, authenticate via browser, etc.).

Now you may benefit from using ' fine grained tokens '

Available here if you're logged into github: https://github.com/settings/tokens

Set up your token then either clone the repo using git clone https://username:github_pat_token@github.com/ExampleOwner/example-repo.git

or just set the remote url if already cloned git remote set-url origin https://username:github_pat_token@github.com/ExampleOwner/example-repo.git

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM