解決mac電腦上出現Permission to xxx.git denied to xxx的問題

第一次用mac從我的github上導下項目,結果在修改之後想push上去的時候突然出現問題了,這部電腦之前是其他人用的,那個xxx就是他的賬號,出現該問題後,針對問題,一下子就百度出了一些解決方法,但是一一試過之後還是沒辦法解決,問題如下:

yidont:VtBanner mac_xihao$ git push origin master
remote: Permission to voctex/VtBanner.git denied to xxx.
fatal: unable to access 'https://github.com/voctex/VtBanner.git/': The requested URL returned error: 403
我把我試過的一些方法都記錄一下:
1、清除ssh_key

打開終端,輸入

cd ~/.ssh

然後就進入.ssh目錄了,輸入

ls

查看目錄下文件

yidont:.ssh mac_xihao$ ls
config      id_rsa      id_rsa.pub  known_hosts

其中id_rsa是你的私鑰,而帶後綴pub的id_rsa.pub文件是你的公鑰,其中公鑰是要給服務器那邊配置的。

可以輸入open 用文件夾打開

yidont:.ssh mac_xihao$ open .

我是直接把該目錄下的文件都刪了,然後重新生成公鑰和密鑰。

yidont:.ssh mac_xihao$ ssh-keygen -t rsa -C "[email protected]"(這裏建議輸入你的郵箱地址)

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/yidont/.ssh/id_rsa):
(這裏要你輸入存放的目錄,好像回車是默認,我沒試過回車)
/Users/yidont/.ssh/id_rsa

Enter passphrase (empty for no passphrase): (輸入ssh密碼)
Enter same passphrase again: (確認密碼)

Your identification has been saved in /Users/yidont/.ssh/id_rsa.
Your public key has been saved in /Users/yidont/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1gepuxDHwJRnFbKvc0Zq/NGrFGE9kEXS06jxatPPrSQ voctex@163.com
The key's randomart image is:
+---[RSA 2048]----+
|      ....=*oo   |
|     o. ooo=+ .  |
|      oo. =+o.   |
|       o =.o..   |
|      . S =o.    |
|       = =++.    |
|      . B.=.Eo.. |
|       o B . +o .|
|          . o.. .. |
+----[SHA256]-----+
yidont:.ssh mac_xihao$ ls
id_rsa    known_hosts    id_rsa.pub 

然後把pub文件裏面的值配置到你的github裏面的ssh_key

2、將git默認的遠程倉庫改爲你自己的那個,並且改掉host

yidont:.ssh mac_xihao$ git remote -v
origin  https://git.oschina.net/xxx/YidontUtils.git (fetch)
origin  https://git.oschina.net/xxx/YidontUtils.git (push)
yidont:.ssh mac_xihao$ git remote set-url origin https://github.com/voctex/VtBanner.git
yidont:.ssh mac_xihao$ git remote -v
origin  https://github.com/voctex/VtBanner.git (fetch)
origin  https://github.com/voctex/VtBanner.git (push)
yidont:.ssh mac_xihao$ git remote set-url origin git@github.com:voctex/VtBanner.git
yidont:.ssh mac_xihao$ git remote -v
origin  git@github.com:voctex/VtBanner.git (fetch)
origin  git@github.com:voctex/VtBanner.git (push)

3、添加密鑰到sshAgent代理中

yidont:.ssh mac_xihao$ eval "$(ssh-agent -s)"
Agent pid 2172
yidont:.ssh mac_xihao$ ssh-add id_rsa
Enter passphrase for id_rsa: (輸入ssh密碼)
Identity added: id_rsa (id_rsa)
(測試連接到github網站)
yidont:.ssh mac_xihao$ ssh -T git@github.com
Hi voctex! You've successfully authenticated, but GitHub does not provide shell access.

以上幾個方法都試過,都不能夠幫我解決問題,直到發現了這篇文章才解決了我的問題,
http://blog.csdn.net/hejiamian/article/details/51800763
按照文章裏面說的,我在Android studio裏面的Terminal裏面進行操作,然後順利push了

yidont:VtBanner mac_xihao$ git remote -v
origin  https://github.com/voctex/VtBanner.git (fetch)
origin  https://github.com/voctex/VtBanner.git (push)
yidont:VtBanner mac_xihao$ git remote rm origin
yidont:VtBanner mac_xihao$ git remote add origin git@github.com:voctex/VtBanner.git
yidont:VtBanner mac_xihao$ git remote -v
origin  git@github.com:voctex/VtBanner.git (fetch)
origin  git@github.com:voctex/VtBanner.git (push)

參考博客如下:

1、Git 最著名報錯 “ERROR: Permission to XXX.git denied to user”終極解決方案

2、Git問題總結

3、git使用中遇到的Permission to xxx denied to xxx問題如何解決

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章