如果没有在github配置机器中使用的公钥信息,git clone时可能会报错
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配置本地生成的公钥就行
1、进入~/.ssh/目录
cd ~/.ssh/
2、创建密钥,email可以随便填,一路回车直至完成
ssh-keygen -t rsa -C "your_email@example.com"

3、复制公钥(id_rsa.pub)中的内容,全部复制

从ssh到邮箱结尾
4、将公钥粘贴到github中
进入github,登陆,点击右上角头像,点击setting进入设置

5、在左边栏选择ssh and gpg keys,点击右上方new ssh key,在弹出的窗口中把刚才复制的公钥填进去,可以根据服务器的信息取个名字,方便区分


点击add ssh key完成即可
6、配置完成后,可以在终端中测试是否成功
ssh -T git@github.com

完成后就可以继续clone啦
如果不成功,在~/.ssh/config文件中添加以下配置
Host github.com HostName github.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
浙公网安备 33010602011771号