git clone时报错:Permission denied
阅读原文时间:2023年09月05日阅读:1

执行git clone git@github.com:T-Better/Soft_test.git时报错:\302\226git@github.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 clone时发现报错:
\302\226git@github.com: Permission denied (publickey).fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

1.ssh key有问题,具体原因忘了

重新生成ssh-key并添加到github中:

解决步骤: 

1. 生成新的SSH key

   如果是客户端与服务端未生成ssh key,那么直接使用:ssh-keygen -t rsa -C "youremail@example.com" 生成新的rsa密钥即可。
   如果是客户端与服务端的ssh key 不匹配,此时需要先将本地生成的 id_rsa以及id_rsa.pub这两个文件【一般在用户名下的.ssh文件夹下】删除掉,然后再使用上述指令生成新的rsa密钥。

补充:ssh-keygen -t rsa -b 4096 -C "邮箱":这条命令的目的是为了让本地机器ssh登录远程机器上的GitHub账户无需输入密码。
ssh-keygen(基于密匙的安全验证):需要依靠密钥进行安全验证,必须为自己创建一对密钥,并把公用密钥放在需要访问的服务器上。
-t 即指定密钥的类型。密钥的类型有两种,一种是RSA,一种是DSA。
-b 指定密钥长度。对于RSA密钥,最小要求768位,默认是2048位。命令中的4096指的是RSA密钥长度为4096位。DSA密钥必须恰好是1024位(FIPS 186-2 标准的要求)。
-C 表示要提供一个新注释,用于识别这个密钥。“”里面不一定非要填邮箱,可以是任何内容,邮箱仅仅是识别用的key。

  2. 将SSH key 添加到 ssh-agent  

使用 ssh-add ~/.ssh/id_rsa 将产生的新ssh key添加到ssh-agent中:

补充: 如果出现“Could not open a connection to your authentication agent.”的错误可以使用以下两种方式解决:
eval "$(ssh-agent -s)"

或者:
eval `ssh-agent`

然后再次执行 ssh-add ~/.ssh/id_rsa 指令。

3. 将SSH key 添加到你的GitHub账户

在账户选项中选择 “Settings”–>“SSH and GPG keys”–>“New SSH key”,然后打开之前新生成的id_rsa.pub文件,将密钥复制后填写到账户中【注意填写时的格式要求】:

4. 验证key

使用 ssh -T git@github.com 对ssh key 进行验证:

当出现上述界面时说明配置成功,此时可以再次执行git push 操作将本地仓库推送到远程。

注: 以上操作命令均在 Git Bash 中完成。

“fatal: Could not read from remote repository.“报错也可用上法

解决办法转自:https://blog.csdn.net/weixin_40922744/article/details/107576748
声明:本文章是在以上地址博文基础上进行整理学习,如有侵权,请联系博主删除,感谢知识共享,一起进步,加油鸭