git@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.
大概率是秘钥设置不对的问题
首先检查有没有在GitHub的https://github.com/settings/keys上添加你本机的SSH key。注意换了电脑是要重新添加的,每台都不一样。添加SSH key的方法:(引自廖雪峰老师的教程)
创建SSH Key。在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa
和id_rsa.pub
这两个文件,如果已经有了,可直接跳到下一步。如果没有,打开Shell(Windows下打开Git Bash),创建SSH Key:
$ ssh-keygen -t rsa -C "youremail@example.com"
你需要把邮件地址换成你自己的邮件地址,然后一路回车,使用默认值即可,由于这个Key也不是用于军事目的,所以也无需设置密码。
如果一切顺利的话,可以在用户主目录里找到.ssh
目录,里面有id_rsa
和id_rsa.pub
两个文件,这两个就是SSH Key的秘钥对,id_rsa
是私钥,不能泄露出去,id_rsa.pub
是公钥,可以放心地告诉任何人。
登陆GitHub,打开“Account settings”,“SSH Keys”页面:
然后,点“Add SSH Key”,填上任意Title,在Key文本框里粘贴id_rsa.pub
文件的内容:
点“Add Key”,你就应该看到已经添加的Key:
? 如果添加了还是出现这个问题,那么问题大概率就定位在了你本机的这个git仓库并没有和这个SSH key 关联上。用下述方法解决:
ssh-add "你的 id-rsa 文件地址"
# 注意这里ssh-add后面填的是私钥地址,如mac电脑是 /Users/用户名/.ssh/id_rsa
ssh -T git@github.com
Hi chenyangdeng! You‘ve successfully authenticated, but GitHub does not provide shell access.
#验证是不是添加成功
git@github.com: Permission denied (publickey). fatal: Could not read from remote repository 解决方法
原文:https://www.cnblogs.com/xxyang/p/13751249.html