Git SSH 错误:“连接到主机:错误的文件号" [英] Git SSH error: "Connect to host: Bad file number"

查看:15
本文介绍了Git SSH 错误:“连接到主机:错误的文件号"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I followed the git guide but I have this strange issue when trying to connect to 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

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

This is my config file under .ssh

Host github.com
    User git
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile "C:Documents and Settingsmugues.sshid_rsa"
    TCPKeepAlive yes
    IdentitiesOnly yes

有什么想法吗?

推荐答案

在我自己遇到这个问题后,我找到了一个适合我的解决方案:

After having this problem myself, I found a solution that works for me:

错误信息:

    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

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

You will only see the bad file number message when on windows using the MINGGW shell. Linux users will just get Timed out.

问题:

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

SSH is probably blocked on port 22. You can see this by typing

    $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

如您所见,状态为已过滤,这意味着有什么东西在阻止它.您可以通过对端口 443 执行 SSH 来解决此问题(您的防火墙/ISP 不会阻止此操作).同样重要的是,您需要 ssh 到ssh.github.com"而不是 github.com.否则,您将向 web 服务器而不是 ssh 服务器报告.以下是解决此问题所需的所有步骤.

As you can see the state is Filtered, which means something is blocking it. You can solve this by performing an SSH to port 443 (your firewall / isp will not block this). It is also important that you need to ssh to "ssh.github.com" instead of github.com. Otherwise, you will report to the webserver instead of the ssh server. Below are all the steps needed to solve this problem.

解决方案:

(首先确保您生成的密钥如 http://help.github.com/win-set-up-git/)

(First of all make sure you generated your keys like explained on http://help.github.com/win-set-up-git/)

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

create file ~/.ssh/config (ssh config file located in your user directory. On windows probably %USERPROFILE%.sshconfig

在其中粘贴以下代码:

    Host github.com
    User git
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443

保存文件.

像往常一样执行 ssh:

Perform ssh like usual:

$ssh -T github.com 
    $Enter passphrase for key '.......... (you can smile now :))

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

Note that I do not have to supply the username or port number.

这篇关于Git SSH 错误:“连接到主机:错误的文件号"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆