Permission denied when pushing file to remote

做~自己de王妃 提交于 2019-12-06 11:38:02

问题


I previously used git bash for local repository.
I have connected to a GitHub account and I always pushed my files without any problem.
Later, I have uninstall the bash and reinstall again with new user and email. Now when I try to push the file to remote I got an error:

 Permission to SyedMiraj/SpringSecurityWithTicketBooking.git denied to biid-sua.
 unable to access 'https://github.com/SyedMiraj/SpringSecurityWithTicketBooking.git/': The requested URL returned error: 403

I have tried and created a new SSH key and add it in the remote repo.
But the problem is still existing and truly speaking I can't push anything to my remote.
My two GitHub accounts are biid-sua and smiraj.

How would you propose to restore GitHub pushes?


回答1:


A couple of points here:

  • the user and email used to make commits have nothing to do with the remote repo (here hosted on GitHub) for authentication
  • SSH keys (old or new) are not used at all when pushing to GitHub with an https URL.
    If it uses your first biid-sua account, this is because of a git credential helper, that has cached your biid-sua credentials for github.com.

You can either make sure and delete that entry (either on Mac or on Windows). You will be prompt for your new username/password at the next push.

Or you can swtich to an SSH URL:

cd /path/to/my/local/repo
git remote set-url origin g2:SyedMiraj/SpringSecurityWithTicketBooking.git

And then make sure your ~/.ssh/config defines the g2 entry and references the right key (as I explain here)

#Account one
Host g1
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa_biid-sua
    User git

#Account two
Host g2
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/yourname/.ssh/id_rsa_smiraj
    User git

Assuming that you have name your SSH keys in HOME:

  • .ssh/id_rsa_biid-sua and .ssh/id_rsa_biid-sua.pub
  • .ssh/id_rsa_smiraj and .ssh/id_rsa_smiraj.pub



回答2:


you need to change your repo config on your PC to ssh way: refer



来源:https://stackoverflow.com/questions/47974196/permission-denied-when-pushing-file-to-remote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!