解决[email protected]: Permission denied (publickey). Could not read from remote repository

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第1张图片

原因分析

Permission denied (publickey) 没有权限的publickey ,出现这错误一般是以下两种原因

  • 客户端与服务端未生成 ssh key
  • 客户端与服务端的ssh key不匹配

找到问题的原因了,解决办法也就有了,重新生成一次ssh key ,服务端也重新配置一次即可。

客户端生成ssh key

ssh-keygen -t rsa -C "[email protected]"

[email protected]改为自己的邮箱即可,途中会让你输入密码啥的,不需要管,一路回车即可,会生成你的ssh key。(如果重新生成的话会覆盖之前的ssh key。) 

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第2张图片

然后再终端下执行命令:

ssh -v [email protected]

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第3张图片

最后两句会出现

  No more authentication methods to try.  
  Permission denied (publickey).

在终端再执行以下命令

ssh-agent -s 

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第4张图片

接着在执行

ssh-add ~/.ssh/id_rsa

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第5张图片

$ ssh-add ~/.ssh/id_rsa
出现Could not open a connection to your authentication agent.
这时可以使用:ssh-agent bash 命令,然后再次使用ssh-add ~/.ssh/id_rsa_name这个命令就没问题了。
如下:

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第6张图片

Identity added: ...这是ssh key文件路径的信息

配置服务端

打开你刚刚生成的id_rsa.pub,将里面的内容复制,进入你的github账号,在settings下,SSH and GPG keys下new SSH key,然后将id_rsa.pub里的内容复制到Key中,完成后Add SSH Key。

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第7张图片

title随便起 

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第8张图片

验证Key

ssh -T [email protected] 
$ ssh -T [email protected]
Hi 470812087! You've successfully authenticated, but GitHub does not provide shell access.

解决git@github.com: Permission denied (publickey). Could not read from remote repository_第9张图片

提示:Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. 问题就解决啦

你可能感兴趣的:(Git,git,github,ssh)