【问题标题】:ssh: connect to host port 22: Connection timed outssh:连接到主机端口 22:连接超时
【发布时间】:2022-02-17 17:53:11
【问题描述】:

在我的新工作计算机上安装 git,生成我的 ssh 密钥并将其添加到 gitlab 后,我试图克隆一个项目,但我收到以下错误:

ssh: connect to host <private-domain>.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我还尝试了使用详细选项测试 ssh 连接的命令,我得到了这个:

$ ssh -Tvvv appgit@<private_domain>.com
OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/h/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/h/.ssh/known_hosts2'
debug2: resolving "<private_domain>.com" port 22
debug3: resolve_host: lookup <private_domain>.com:22
debug3: ssh_connect_direct: entering
debug1: Connecting to <private_domain>.com [<serv.ip.add.ress>] port 22.
debug3: set_sock_tos: set socket 4 IP_TOS 0x48
debug1: connect to address <serv.ip.add.ress> port 22: Connection timed out
ssh: connect to host <private_domain>.com port 22: Connection timed out

我知道域存在,ping &lt;private-domain&gt;.com 有效。我不认为这是代理问题,因为我没有使用 http 或 https 连接。

this answer 中的修复都没有改变任何东西。 (我在 Windows 上)


我注意到,如果我删除 ~/.ssh 文件夹中的密钥,我会收到同样的错误,这让我认为这是一个密钥问题,而不是网络问题。如何确定 git 使用的是正确的密钥?

我已经尝试ssh-keygen -lf ~/.ssh/id_rsa -E md5 来查看指纹是否与 gitlab 上的指纹匹配(确实如此),但这只会给我文件夹中的指纹,不一定是 git 使用的指纹。 Git-gui Help&gt;Show SSH Key 确实正确显示了我的密钥。

【问题讨论】:

  • "timed out" 错误通常意味着您正在拨打 Internet 电话并恢复了死寂:它没有发出忙音信号,您没有收到“boo-bah-beep!the您拨打的号码不在服务区”,没有人打招呼,只是……什么都没有。可能你的手机坏了。也许电线被切断了。有很多可能性。
  • ping 对相关名称有效这一事实很有希望。使用您必须使用的任何网络诊断工具来跟踪 ssh 数据包。观察双方(你的一端,服务器主机)。然后一路走到中间,看看哪里出了问题。

标签: git ssh gitlab connection-timeout


【解决方案1】:

仔细检查:

  • 远程服务器至少在端口 22 上应答

      curl -v telnet://<private_domain>.com:22
    

connect to address &lt;serv.ip.add.ress&gt; port 22: Connection timed out 部分似乎表明远程服务器没有监听,或者本地服务器阻止任何出口 SSH 连接)

  • 远程GitLab服务器确实配置了一个名为appgit的技术账户:通常使用的默认账户是git
    以防万一,用ssh -Tvvv git@&lt;private_domain&gt;.com再次测试

并确保您的密钥使用默认命名方案(如~/.ssh/id_rsa[.pub]

【讨论】:

  • appgitgit 给出相同的结果。奇怪的是,如果我从.ssh 文件夹中删除我的密钥,我会收到相同的超时错误(没有“身份验证失败”或“ssh 密钥未授权”错误或类似的错误)。这让我相信这是一个关键问题,而不是网络问题。我怎么知道 git 实际上在正确的文件夹中使用了正确的键?
  • @TeleportingGoat 这意味着 Git 甚至没有机会使用正确的密钥:网络问题阻止它联系远程端的端口 22。
猜你喜欢
  • 2015-09-17
  • 2013-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多