今天用idea提交代码到github上,push后报错
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.

一:原因分析
Permission denied (publickey) 没有权限的publickey ,出现这错误一般是以下两种原因
- 客户端与服务端未生成 ssh key
- 客户端与服务端的ssh key不匹配
找到问题的原因了,解决办法也就有了,重新生成一次ssh key ,服务端也重新配置一次即可。
二:客户端生成ssh key
在cmd里面输入
ssh-keygen -t rsa -C "xxxxxxxx@qq.com"
ssh-keygen -t rsa -C "youremail@example.com"
xxxxxx@qq.com改为自己的邮箱即可,途中会让你输入密码啥的,不需要管,一路回车即可,会生成你的ssh key。(如果重新生成的话会覆盖之前的ssh key。)

三:输入箭头处路径

四:打开id_rsa.pub文件,并且复制内容

配置服务端
五:在github上打开箭头处,点击Setting

六:点击SSH and GPG keys

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

八:然后添加后入下图所示

九:用idea再次提交文件到 github上,显示提交成功
