Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you ha

之前使用git进行push或者clone操作的时候出现如下错误:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

原因:电脑公钥(publickey)未添加至github,所以无法识别。 因而需要获取本地电脑公钥,然后登录github账号,添加公钥至github就OK了。

设置Git的user nameemail

git config --global user.name "yourname"
git config --global user.email "youremail" 

生成SSH密钥

查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
生存密钥:
ssh-keygen -t rsa -C “youremail”
按3个回车,密码为空。
Your identification has been saved in /home/tekkub/.ssh/id_rsa.Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.The key fingerprint is:
………………
最后得到了两个文件:id_rsaid_rsa.pub

在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥。打开github在设置中添加密钥

按照指令操作会进入vim编辑模式,上边的序列码即为公钥,复制序列码,包含(ssh-rsa等标识)。不同操作系统和电脑可能公钥路径不一样,以实际情况为准.
登录github后,进入个人设置settings--->ssh and gpg keys-->new ssh key 添加即可。title自行命名

add ssh key成功后,github就可以识别你的机器,允许你从github拉取代码了。

原文地址:https://www.cnblogs.com/lxwphp/p/15453086.html