克隆git代码到本地时报“fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.”


克隆代码时报错:git@gitee.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

怎么解决:

先查看当前的账号和邮箱,

git config user.name

git config user.email

如果有误的话可以切换用户名和邮箱:

git config --global user.name "xxx"

git config --global user.email "xxx"

如果没错的话,很可能就是不同设备上的ssh公钥不同,比如我有两台电脑,其中git仓库用的是其中一台电脑产生的ssh公钥()但不同设备产生的公钥是不能互用的,所以如果要克隆git上的代码到另一台设备上,就需要让另一台设备产生的公钥也添加到git上

生成公钥的命令:

ssh-keygen -t rsa -C "xxxxx@xxxxx.com" 
接下来终端显示的内容就是需要你回车和输入密码了 中文翻译 🔽 生成公共/私有rsa密钥对 输入保存密钥的文件(/Users/jiangpeng/.ssh/id_rsa): /用户/ jiangpeng /。ssh / id_rsa已经存在。 覆盖(y / n) ?y (下面会让你输入密码,我也不清楚,我随意的输入六位密码) Enter passphrase (empty for no passphrase): Enter same passphrase again:


如果另一台设备已经生成了公钥,那么再次执行生成公钥的命令时,
就会提示是否覆盖,选中否,然后在提示已有的公钥路径去找
一般是这个:

 

 

 

 在这个目录下右键,git bush here

然后cat id_rsa.pub查看公钥内容。然后复制下来。

在gitee中添加这个公钥:

 

 之后就可以在指定目录进行克隆目标仓库了:git clone 仓库路径


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM