git报错-git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

git报错

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

【解决方案】

1、配置ssh

设置Git的user name和email

git config –global user.name “yourname” 
git config –global user.email “youremail” 
生成SSH密钥

查看是否已经有了ssh密钥:cd ~/.ssh 

打开id_rsa.pub文件,复制内容粘贴到下面图示的位置

  

2、本次我遇到的问题是已经添加了sshkey,但还是一直报错

 该问题的原因是我本地有两个sshkey,一个公司的,一个个人的;

所以需要解决的问题就是如何本地配置多个sshKey

【解决方案】:在.ssh目录下新建config文件,如图所示:

在config文件里面添加:vim config

# github
Host github.com
Port 22
HostName github.com
PreferredAuthentications publickey
IdentityFile C:\Users\username\.ssh/id_rsa_github
User yourname
 
# companygit
Host companygit
HostName companygit
PreferredAuthentications publickey
IdentityFile C:\Users\username\.ssh/id_rsa
User yourname

 最后去检查是否成功:

ssh -T git@github.com

如果出现下面的提示即为成功

 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值