【工具使用】WebStorm 连接github 出现 invalid host key ssh-rsa 问题的解决

本地git配置远程ssh连接github仓库

无法提交报Push failed
Invald host key ssh-rsa 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
java.io.IOException: There was a problem while connecting to github.com:22
at com.trilead.ssh2.Connection.connect(Connection.java:834)
at com.trilead.ssh2.Connection.connect(Connection.java:703)
at com.trilead.ssh2.Connection.connect(Connection.java:617)
at org.jetbrains.git4idea.ssh.SSHMain.start(SSHMain.java:160)
at org.jetbrains.git4idea.ssh.SSHMain.main(SSHMain.java:124)
Caused by: java.io.IOException: Key exchange was not finished, connection is closed.
at com.trilead.ssh2.transport.KexManager.getOrWaitForConnectionInfo(KexManager.java:95)
at com.trilead.ssh2.transport.TransportManager.getConnectionInfo(TransportManager.java:237)
at com.trilead.ssh2.Connection.connect(Connection.java:786)
… 4 more
Caused by: java.io.IOException: The server hostkey was not accepted by the verifier callback
at com.trilead.ssh2.transport.KexManager.handleMessage(KexManager.java:548)
at com.trilead.ssh2.transport.TransportManage… (show balloon)错误

1. 为git添加环境变量

1551885516278

2.1 配置本地./ssh文件

参见:https://zhidao.baidu.com/question/1303468264429394659.html回答;

============

1、首先,使用两个git config ...命令设置用户名和电子邮件地址,然后使用ssh-keygen命令生成一对rsa密钥。

2、生成后,根据输出提示,打开存储密钥的文件夹,可以看到两个文件。私钥,公钥。使用文本编辑器打开id_rsa.pub文件。稍后将使用该副本的内容。

3、登录github,单击您的头像并转到“设置”设置。

4、切换到SSH和GPG密钥,然后单击SSH密钥右侧的新SSH密钥。

5、然后在添加新页面上,上面的标题写入标题并粘贴刚刚复制的公钥。

6、保存如下图所示。它可以使用。

============

Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置。
github的SSH配置如下:
1 、设置Git的user name和email:
$ git config --global user.name "xuhaiyan"
$ git config --global user.email "haiyan.xu.vip@gmail.com"

2、生成SSH密钥过程:
1)查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
2)生存密钥:
$ ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
按3个回车,密码为空。

Your identification has been saved in /home/tekkub/.ssh/id_rsa.
Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
The key fingerprint is:

最后得到了两个文件:id_rsa和id_rsa.pub

3)添加密钥到ssh:ssh-add 文件名
需要之前输入密码。

4)在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥。
打开https://github.com/ ,登陆xuhaiyan825,然后添加ssh。

5)测试:ssh git@github.com
The authenticity of host ‘github.com (207.97.227.239)’ can’t be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.

2.2 在 安装的 id_rsa.pub文档中,用记事本打开,复制文本到github添加sshkeys

1551886695725

1551886584823

添加后发现./ssh文件中多了know_hosts文件,说明配置成功

接下来就可以开心地用git

add-commit 本地仓库 和push,pull github上的项目啦

avatar


若文章对您有帮助,帮忙点个赞!

0
-5
发布时间 2021-10-07 20:09:50
0 条回复(回复会通过微信通知作者)
点击加载更多评论
登录 后再进行评论
(微信扫码即可登录,无需注册)