Git SSH错误:"连接到主机:错误的文件号"

Mas*_*ues 153 git ssh github

我按照git指南但在尝试连接到github时遇到了这个奇怪的问题:

$ ssh -v git@github.com
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /c/Documents and Settings/mugues/.ssh/config
debug1: Applying options for github.com
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: connect to address 207.97.227.239 port 22: Attempt to connect timed out without establishing a connection
ssh: connect to host github.com port 22: Bad file number
Run Code Online (Sandbox Code Playgroud)

这是我在.ssh下的配置文件

Host github.com
    User git
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile "C:\Documents and Settings\mugues\.ssh\id_rsa"
    TCPKeepAlive yes
    IdentitiesOnly yes
Run Code Online (Sandbox Code Playgroud)

任何的想法?

Sam*_*Sam 186

在遇到这个问题后,我找到了一个可行的解决方案.

错误信息:

    ssh -v git@github.com
    OpenSSH_5.8p1, OpenSSL 1.0.0d 8 Feb 2011
    debug1: Connecting to github.com [207.97.227.239] port 22.
    debug1: connect to address 207.97.227.239 port 22: Connection timed out
    ssh: connect to host github.com port 22: Connection timed out
    ssh: connect to host github.com port 22: Bad file number
Run Code Online (Sandbox Code Playgroud)

在Windows上使用MINGGW shell时,您只会看到错误的文件编号消息.Linux用户只会获得Timed.

问题:

SSH可能在端口22上被阻止.您可以通过键入来查看

    $nmap -sS github.com -p 22
    Starting Nmap 5.35DC1 ( http://nmap.org ) at 2011-11-05 10:53 CET
    Nmap scan report for github.com (207.97.227.239)
    Host is up (0.10s latency).
    PORT   STATE    SERVICE
    22/tcp ***filtered*** ssh

    Nmap done: 1 IP address (1 host up) scanned in 2.63 seconds
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,状态是Filtered,这意味着某些东西阻止了它.您可以通过执行SSH到端口443(您的防火墙/ isp不会阻止此)来解决此问题.什么也很重要,你需要ssh到"ssh.github.com"而不是github.com.否则,您将向网络服务器而不是ssh服务器报告.下面解决这个问题所需的所有步骤.

解:

(首先要确保你生成了你的密钥,如http://help.github.com/win-set-up-git/上所述)

创建文件〜/ .ssh/config(位于用户目录中的ssh配置文件.可能在Windows上 %USERPROFILE%\.ssh\config

将以下代码粘贴到其中:

    Host github.com
    User git
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443
Run Code Online (Sandbox Code Playgroud)

保存文件.

像往常一样执行ssh:

$ssh -T github.com 
    $Enter passphrase for key '.......... (you can smile now :))
Run Code Online (Sandbox Code Playgroud)

请注意,我不必提供用户名和端口号.

  • 我改为`ssh:connect to host ssh.github.com port 443:Bad file number` (27认同)
  • 换句话说,您建立[通过HTTPS端口的SSH连接](https://help.github.com/articles/using-ssh-over-the-https-port). (4认同)
  • 在Windows 7上使用`.ssh/config`文件时,请确保你有一个用户环境Var`HOME`,其中'%USERPROFILE%`作为值 - >帮助我,当我的ssh找不到它时 (2认同)

Sté*_*hon 40

关键信息是用@ Sam的答案写的,但不是很显着,所以让我们说清楚.

"错误的文件编号"没有提供信息,它只是在Windows上运行git的ssh的一个标志.

甚至没有-v开关出现的线:

ssh: connect to host (some host or IP address) port 22: Bad file number
Run Code Online (Sandbox Code Playgroud)

实际上是无关紧要的.

如果你专注于它,你会浪费你的时间,因为它不是一个关于实际问题的暗示,只是在Windows上运行git的ssh的效果.它甚至不是git或ssh安装或配置错误的标志.真的,忽略它.

在Linux上使用相同的命令为我生成了这条消息,它提供了有关该问题的实际提示:

ssh: connect to host (some host or IP address) port 22: Connection timed out
Run Code Online (Sandbox Code Playgroud)

实际解决方案:忽略"错误的文件编号"并获取更多信息

专注于-v在命令行上添加的行.在我的情况下它是:

debug1: connect to address (some host or IP address) port 22: Attempt to connect timed out without establishing a connection
Run Code Online (Sandbox Code Playgroud)

我的问题是IP地址中的拼写错误,但您的问题可能有所不同.

这个问题是关于"错误的文件编号",还是关于连接超时的原因有多少?

如果有人能够证明只有在实际原因是"连接超时"时才出现"坏文件编号",那么解决连接可能会超时的原因是有意义的.

在此之前,"错误的文件编号"只是一般错误消息,并且通过说"忽略它并查找其他错误消息"来完全回答这个问题.

编辑:Qwertie提到错误消息确实是通用的,因为它也可能发生在"连接拒绝"上.这证实了分析.

请不要将这个问题与一般提示和答案混为一谈,它们与此问题的实际主题(和标题)无关,即"Git SSH错误:"连接到主机:错误的文件号"".如果使用-v你有更多信息性的消息,值得他们自己的问题,然后打开另一个问题,然后你可以建立一个链接.


小智 15

这对我有用:

ssh -v git@github.com -p 443
Run Code Online (Sandbox Code Playgroud)


Ger*_*ger 5

也许您的防火墙或阻止程序应用程序(PeerBlock等)阻止了您的端口


Fos*_*tah 5

您还可以尝试:

telnet example.com 22
Run Code Online (Sandbox Code Playgroud)

查看您是否连接到服务器.我看到了这条消息,最终我正在阻止访问的VPN.脱离VPN,我很高兴.