解决mac电脑上出现Permission to xxx.git denied to xxx的问题

xiaoxiao2021-02-27  315

第一次用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 "voctex@163.com"(这里建议输入你的邮箱地址) 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问题如何解决

转载请注明原文地址: https://www.6miu.com/read-5127.html

最新回复(0)