连接服务端的gitlab时出现ssh_exchange_identification: read: Connection reset by peer

问题由来:

本机执行git push时出现ssh_exchange_identification: read: Connection reset by peer fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

进行ssh调试:

gg@DESKTOP-STOOSVR MINGW64 ~/Desktop
$ ssh -v git@118.25.6.666
OpenSSH_7.9p1, OpenSSL 1.1.1a  20 Nov 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 118.25.6.666 [118.25.6.666] port 22.
debug1: Connection established.
debug1: identity file /c/Users/gg/.ssh/id_rsa type 0
debug1: identity file /c/Users/gg/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/gg/.ssh/id_dsa type -1
debug1: identity file /c/Users/gg/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/gg/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/gg/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/gg/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/gg/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/gg/.ssh/id_xmss type -1
debug1: identity file /c/Users/gg/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
ssh_exchange_identification: read: Connection reset by peer

百思不得其姐,显示能够与之通信但是被拒绝连接,研究了好几秒恍然大悟,自己以前对可通过ssh连接的ip进行了限制,使用时的ip不在通行列表,导致ssh连接被拒绝,解决此问题很简单:
1、在/etc/hosts.allow中添加对外ip(公网的那种,百度搜ip会显示出来的那个)

[root@VM_0_13_centos ~]# vim /etc/hosts.allow 
sshd:106.66.*.*,107.7.*.*:allow  # 示例ip

或者直接在hosts.allow 键入sshd:ALL # 不限制可通过ssh登录的ip

2、重启sshd

[root@VM_0_13_centos ~]# /bin/systemctl restart sshd.service
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:设计师小姐姐 返回首页