ssh: connect to host github.com port 22: Bad file number

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

This is my config file under .ssh

Host github.com
    User git
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile "C:\Documents and Settings\mugues\.ssh\id_rsa"
    TCPKeepAlive yes
    IdentitiesOnly yes

Any idea?

Kind regardsMassimo

share | improve this question
 
 
Got this today. And it seems Github was down. –  ysrb Apr 27 at 15:38

15 Answers

up vote 119 down vote accepted

After having this problem myself i found a working solution for me.

Error message:

    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

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

Problem:

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

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 wont block this).Whats also important that you need to ssh to "ssh.github.com" instead of github.com.Else you will report to the webserver instead of ssh server.Below all the steps needed to solve this problem.

Solution:

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

create file ~/.ssh/config (ssh config file located in your user directory. On windows probably C:\Users\USERNAME\.ssh\config

Paste the following code in it:

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

Save the file.

Perform ssh like usual:

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

Note that i dont have to supply the username nor port number.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
问题描述中提到了在使用Ubuntu系统时出现了"ssh: connect to host github.com port 22: Connection timed out"的错误。这个错误表示连接到github.comSSH端口22超时了。为了解决这个问题,可以尝试以下方法: 1. 修改SSH配置文件: - 打开终端并输入以下命令:`sudo vim /etc/ssh/ssh_config` - 找到`#Port 22`这一行(可能是注释状态),将其修改为`Port 443`(如果没有这一行,可以直接添加) - 保存并退出配置文件 - 重新连接到github.com,看是否问题已经解决 2. 使用不同的SSH命令: - 打开终端并输入以下命令:`ssh -T git@ssh.github.com` 或 `ssh -T -p 443 git@github.com` - 如果连接成功并显示"You've successfully authenticated",则说明问题已解决;如果仍然显示"ssh: connect to host github.com port 22: Connection timed out",则继续尝试以下命令 - 输入命令:`ssh -T -p 443 git@ssh.github.com` - 检查是否有异常信息显示 3. 配置新的端口: - 打开终端并输入以下命令:`cd ~/.ssh && vim config` - 在编辑器中添加以下内容并保存退出: ``` Host github.com User git Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 443 ``` - 重新连接到github.com,看是否问题已经解决 这些方法应该能帮助您解决Ubuntu系统中的"ssh: connect to host github.com port 22: Connection timed out"错误。记得在尝试这些方法之前先备份您的SSH配置文件,以防出现意外情况。希望对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值