58

我在win7工作并使用sshd设置git服务器。I git --bare init myapp.git,并正确克隆ssh://git@localhost/home/git/myapp.gitCywgin中。但是我又需要配置Cygwin的 git ,我想在Git Bash中进行 git clone 。我运行git clone ssh://git@localhost/home/git/myapp.git并收到以下消息

ssh_exchange_identification: Connection closed by remote host

然后我ssh -vvv git@localhostGit Bash中运行并收到消息

debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /c/Users/MoreFreeze/.ssh/identity type -1
debug3: Not a RSA1 key file /c/Users/MoreFreeze/.ssh/id_rsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace 
// above it repeats 24 times
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /c/Users/MoreFreeze/.ssh/id_rsa type 1
debug1: identity file /c/Users/MoreFreeze/.ssh/id_dsa type -1
ssh_exchange_identification: Connection closed by remote host

看来我的私钥格式错误?BEGIN而且我发现没有and的私钥中正好有 25 行END。我很困惑为什么它说不是 RSA1 密钥,我完全确保它是 RSA 2 密钥。

欢迎任何建议。顺便说一句,我已经阅读了谷歌关于这个问题的前 3 页。

4

28 回答 28

72

我今天遇到了这个问题,我意识到我连接到了 2 个不同的网络(LAN 和 WLAN),我解决了这个问题,只是从我的以太网适配器上断开了电缆。我想这个问题是因为 ssh 密钥与我的无线适配器的 MAC 地址绑定的。我希望这可以帮助你。

于 2012-09-19T21:36:51.297 回答
27

我今天刚刚遇到这个问题,这是因为我试图连接的服务器处理过多。因此,服务器可能内存不足或 CPU 不足。

于 2013-04-04T21:56:12.960 回答
16

只需在服务器端输入:

echo 'SSHD: ALL' >> /etc/hosts.allow

它为我整理好了。

于 2013-08-12T12:09:21.610 回答
13

在linux中点击以下ssh restart命令

prayag@prayag:~/backup/NoisyNeighbour$ service ssh restart 
stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.75" (uid=1417676764 pid=5933 comm="stop ssh ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.76" (uid=1417676764 pid=5930 comm="start ssh ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
于 2014-02-21T05:10:42.810 回答
13

要解决问题,请在上添加 Git 的主机名~/.ssh/config

Host github.com
 Hostname ssh.github.com
 Port 443

在我的情况下,github!

于 2020-04-02T14:43:39.167 回答
11

确保您没有连接到任何类型的 VPN。

于 2013-04-05T18:33:28.280 回答
5

得到同样的错误信息。关闭 WiFi 并重新打开它对我有用。

于 2014-07-13T15:21:08.880 回答
5

删除/删除后rm ~/.ssh/known_hosts,我的问题得到了解决

于 2019-04-08T05:14:09.050 回答
3

如果主机名不起作用,请尝试 IP 地址。

这正在发生,所以我不得不说。我尝试使用我的主机名 ssh,但它不起作用

ssh root@host.example.net

这给出了错误“ssh_exchange_identification:连接被远程主机关闭”

这曾经工作一小时。

但是,这是有趣的部分,IP 地址有效!

ssh root@192.168.0.100

(当然实际IP地址不同)

去搞清楚!

于 2013-07-17T13:35:38.417 回答
3

我在将 /etc/ssh/sshd_config 中的 ssh 端口和 MaxStartups 变量更改为后解决了这个问题,

port 2244
MaxStartups 100

然后,重启服务

service sshd restart

如果仍然无法正常工作,请重新启动系统。

于 2017-05-31T06:56:25.200 回答
1

嗨,我在一个 vps 服务上修复了这个问题,重新启动它,另一种方法是,如果您有来自服务的控制台或任何其他方式在远程机器上运行命令,您必须运行的唯一命令是重新启动 ssh 守护程序并享受!:P

/etc/init.d/ssh restart
于 2014-01-15T16:54:19.567 回答
1

我们今天早上将我们的 git 主机实例/服务器迁移到了一个新的数据中心,并且在连接到两者时:VPN(来自远程/家庭)或在办公室网络中时,我遇到了同样的错误并且无法连接以克隆任何 GIT回购。

Cloning into 'some_repo_in_git_dev'...
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

如果您通过跳转主机服务器连接到部分或所有服务器,这将有所帮助。

在我的~/.ssh/config 文件中,我的连接设置是:

Host * !ssh.somejumphost.my.company.com
     ProxyCommand ssh -q -W %h:%p ssh.somejumphost.my.company.com

这意味着,对于任何基于 SSH 的连接,它将通过给定的跳转主机服务器连接到任何*服务器,除了/忽略“ssh.somejumphost.my.company.com”服务器(因为我们不想连接到通过跳转主机服务器的跳转主机。

为了解决这个问题,我所做的只是将配置更改为也忽略 git 服务器:

Host * !ssh.somejumphost.my.company.com !mycompany-git.server.com !OrMyCompany-some-other-git-instance.server.com
     ProxyCommand ssh -q -W %h:%p ssh.somejumphost.my.company.com

所以,现在要在执行 git clone(git SSH url)时连接到 mycompany-git.server.com,我告诉 SSH 不要为这两个额外的 git 实例/服务器使用跳转主机。

于 2017-07-06T17:31:40.827 回答
1

与 Arun Sangal 类似,问题出在 .ssh/config 条目中

Host my.sshhost.com
  ProxyCommand ssh -q -W %h:%p myremotemachine.my.company.com

添加了远程机器以避免使用 ssh 进行 VPN 连接并且运行良好。但是在假期期间,我关闭了 myremotemachine 并遇到了所描述的问题。

于 2018-12-28T10:04:46.307 回答
1

我今天经历了这一点,我只是做了一个:

12345@123456 MINGW64 ~/development/workspace/test (develop)
$ git status
Refresh index: 100% (1204/1204), done.
On branch develop
Your branch is up to date with 'origin/develop'.

nothing to commit, working tree clean

12345@123456 MINGW64 ~/development/workspace/test (develop)
$ git fetch

然后一切又开始了。

于 2019-09-05T05:27:52.980 回答
1

要解决此问题,请编辑 /etc/ssh/ssh_config 并注释以下第 1 行

代理命令 /usr/bin/sss_ssh_knownhostsproxy -p %p %h

https://www.evilbox.ro/linux/solve-ssh_exchange_identification-connection-closed-by-remote-host/供参考

于 2020-04-11T17:48:48.363 回答
1

删除任何配置~/.ssh/config或其他 ssh 配置位置,这将不允许它访问 Github 服务器

在我的情况下,它低于配置,并且我没有连接到 VPN。

Host *
  ProxyJump 10.0.0.50 

注意:- 如果我连接到 VPN,此配置将意味着 git clone 或任何 git 操作将通过 VPN 发送,这可能会很慢,具体取决于我们使用的 VPN 类型。

于 2020-10-15T16:20:34.777 回答
1

断开并重新连接到当前网络对我有用。

于 2020-11-02T10:15:58.697 回答
1

今天 Gitlab Server 正在维护中。请稍后检查它是否正常工作。

于 2021-05-08T09:35:16.153 回答
0

当我从一个工作场所移动到另一个工作场所时,使用 ssh 连接到 GitHub 时也遇到了同样的错误。根据我的情况,似乎不同网络的dns服务器可能会获得github的各种ip地址,并且在发生更改时known_hosts文件无法识别它。所以更改dns或切换回原始网络可能会起作用。

于 2016-04-20T15:35:49.560 回答
0

sshd如果您的服务无法运行,您可以获得“ssh_exchange_identification:远程主机关闭连接” !

如果您有权访问服务器,请检查您是否sshd正在运行该服务:

  ps aux | grep ssh

并检查它是否正在侦听端口 22:

 netstat -plant | grep :22

更多细节在这里

于 2017-01-21T05:39:07.577 回答
0

对我来说,这是由并发 ssh 会话数的限制引起的。我将下面的两个参数添加到 /etc/ssh/sshd_config 然后一切正常。

echo 'MaxSessions 2000' >> /etc/ssh/sshd_config
echo 'MaxStartups 2000' >> /etc/ssh/sshd_config
service ssh restart
于 2018-02-05T00:04:38.893 回答
0

简单的服务器重启为我解决了这个问题。尝试硬重启,如果软重启后不起作用。

于 2018-07-09T07:26:32.853 回答
0

请使用端口 7999 并尝试。它会起作用的

于 2019-02-24T14:24:00.697 回答
0

我是这样解决的。

ssh -vvv <username>@github.com查看github IP。

然后打开浏览器,通过IP打开github,发现是防火墙的问题。

于 2019-08-29T17:08:41.430 回答
0

对我来说,问题是在 /etc/ssh/ssh_config 中设置了一个代理并且它已关闭,通过将远程 git IP 列入白名单并删除代理行来解决问题。

希望这可以帮助某人。

于 2019-09-25T13:16:19.457 回答
0

在 Windows 机器中,删除 C:\Users{yourusername}.ssh 中存在的配置文件的内容

这对我来说效果很好。

于 2020-02-20T04:30:29.680 回答
0

如果您使用的是 VPN,请将其关闭并再次尝试推送。

于 2020-03-26T13:58:27.750 回答
0

就我而言,我正在开发一个用于设置 Raspberry Pies 的脚本。我忘了添加启用 ssh 的脚本。

于 2021-10-19T10:49:40.310 回答