gitlab服务: kex_exchange_identification: Connection closed by remote host

Posted 格格巫 MMQ!!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gitlab服务: kex_exchange_identification: Connection closed by remote host相关的知识,希望对你有一定的参考价值。

搜索了一圈,其实是基本原理没理解到位。

git clone git@xxx.com:group/project.git实际使用的是SSH协议。多个认证文件存在时,通常需要在config文件中进行类似如下的配置——

需要强调的是:Port端口值是SSH服务的端口,只有在SSH服务的默认端口变更是才需要进行显示配置

Host github.com
# Specifies the real host name to log into. Numeric IP addresses are also permitted.
HostName github.com
# Defines the username for the SSH connection.
User gebitang
# Specifies a file from which the user’s DSA, ECDSA or DSA authentication identity is read.
IdentityFile ~/.ssh/id_rsa
Host prj.geb.cn
HostName prj.geb.cn
# Specifies the port number to connect on the remote host. only if the port for ssh connection is not 22.
Port 8201
# The default is ~/.ssh/identity for protocol version 1, and ~/.ssh/id_dsa, ~/.ssh/id_ecdsa and ~/.ssh/id_rsa for protocol version 2.
IdentityFile ~/.ssh/geb_id_rsa
自己搭建的环境使用的路由器自带的DMZ功能(路由器下的内网中的某台机器作为路由器绑定的静态ip的服务提供商。简单理解为——此静态ip提供的所有服务实际上都来自某台指定的内网机器)

搭建的gitlab服务使用的web服务端口是9527,而不是默认的80端口。使用http地址进行git操作时,提供用户名、密码可以正常进行操作。添加了ed25519格式的SSH key后,一直提示kex_exchange_identification: Connection closed by remote host的错误。执行ssh -vT git@stf.geb-corp.com测试时,提示如下详细信息。配置生效了,

from Mac

~ ssh -vT git@stf.geb-corp.com
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/gebitang/.ssh/config
debug1: /Users/gebitang/.ssh/config line 15: Applying options for stf.geb-corp.com
debug1: /Users/gebitang/.ssh/config line 28: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to stf.geb-corp.com port 9527.
debug1: Connection established.
debug1: identity file /Users/gebitang/.ssh/id_ed25519 type 3
debug1: identity file /Users/gebitang/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: kex_exchange_identification: banner line 0: HTTP/1.1 400 Bad Request
debug1: kex_exchange_identification: banner line 1: Server: nginx
debug1: kex_exchange_identification: banner line 2: Date: Tue, 27 Apr 2021 07:36:29 GMT
debug1: kex_exchange_identification: banner line 3: Content-Type: text/html
debug1: kex_exchange_identification: banner line 4: Content-Length: 150
debug1: kex_exchange_identification: banner line 5: Connection: close
debug1: kex_exchange_identification: banner line 6:
debug1: kex_exchange_identification: banner line 7:
debug1: kex_exchange_identification: banner line 8: 400 Bad Request
debug1: kex_exchange_identification: banner line 9:
debug1: kex_exchange_identification: banner line 10:

400 Bad Request


debug1: kex_exchange_identification: banner line 11:
nginx

debug1: kex_exchange_identification: banner line 12:
debug1: kex_exchange_identification: banner line 13:
kex_exchange_identification: Connection closed by remote host

from Windows

joechin@Gebitang MINGW64 /e/0daywork
$ ssh -vT git@stf.geb-corp.com
OpenSSH_7.7p1, OpenSSL 1.0.2o 27 Mar 2018
debug1: Reading configuration data /c/Users/joechin/.ssh/config
debug1: /c/Users/joechin/.ssh/config line 8: Applying options for stf.geb-corp.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to stf.geb-corp.com [10.112.78.174] port 9527.
debug1: Connection established.
debug1: identity file /c/Users/joechin/.ssh/id_ed25519 type 3
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/joechin/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: ssh_exchange_identification: HTTP/1.1 400 Bad Request
debug1: ssh_exchange_identification: Server: nginx
debug1: ssh_exchange_identification: Date: Tue, 27 Apr 2021 08:11:51 GMT
debug1: ssh_exchange_identification: Content-Type: text/html
debug1: ssh_exchange_identification: Content-Length: 150
debug1: ssh_exchange_identification: Connection: close
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification: 400 Bad Request
debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification:

400 Bad Request


debug1: ssh_exchange_identification:
nginx

debug1: ssh_exchange_identification:
debug1: ssh_exchange_identification:
ssh_exchange_identification: Connection closed by remote host
可以在nginx的log下看到10.115.8.73 - - [27/Apr/2021:16:00:41 +0800] “- -” 400 150 “” "-"这样的信息。

实际上就只是端口配置错误了而已~~

以上是关于gitlab服务: kex_exchange_identification: Connection closed by remote host的主要内容,如果未能解决你的问题,请参考以下文章

为啥自建的本地gitlab服务器打开很慢

GitLab服务器迁移

通过文件系统将 Gitlab 存储库复制到另一个 Gitlab 服务器

gitlab服务器迁移

gitlab 优化

搭建GitLab服务器