文章目录
- 前言
- 问题分析
- 解决方法
- 配置客户端
- 配置服务端
- 验证
 
前言
在使用goland从github下载依赖时(git clone github.com/gin-gonic/gin)出现git@github.com:Permission denied(publickey).fatal: Could not read form remote repository错误。
问题分析
Permission denied(publickey):没有权限
 说明github和本地git没有生成ssh key或者ssh key不匹配
解决方法
配置客户端
- 客户端(本文为windows10电脑),打开git bash,执行ssh-keygen -t rsa -C "github登录邮箱"
  
 然后一路回车(不用输入)。
- 在git bash执行ssh -v git@github.com
 出现下方文字
 如图:No more authentication methods to try. Permission denied(publickey) 
- 在git bash执行ssh-agent -s,如图
  
- 在git bash执行ssh-add ~/.ssh/id_rsa,如图
  
 出现Could not open a connection to your authentication agent警告
 在git bash执行ssh-agent bash命令,然后再次执行ssh-add ~/.ssh/id_rsa
  
 Identity added: /c/Users/zhandongyang/.ssh/id_rsa,这是ssh key文件在windows电脑上的位置,用记事本打开这个路径上的id_rsa.pub文件,复制里面的内容。
  
配置服务端
- 本文的服务端为github,访问github网站、登录,点击右上角的头像,然后点击Settings 
- 选择SSH and GPG keys,选择New SSH key
  
 Title写个自己记得住的名字,Key填写复制的id_rsa.pub文件内容
验证
在客户端(本文为windows10电脑)的git bash执行ssh -T git@github.com
 
 至此结束。