ssh:连接到主机端口22:连接超时

问题描述 投票:0回答:4

在我的新工作计算机上安装 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 <private-domain>.com
有效。我不认为这是代理问题,因为我没有使用 http 或 https 连接。

此答案中的任何修复都没有改变任何内容。 (我在Windows上)


我注意到,如果我删除

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

我尝试过

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

git ssh gitlab connection-timeout
4个回答
2
投票

仔细检查:

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

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

connect to address <serv.ip.add.ress> port 22: Connection timed out
部分似乎表明远程服务器不侦听,或者本地服务器阻止任何出口SSH连接)

  • 远程 GitLab 服务器确实配置了一个名为
    appgit
    的技术帐户:通常使用的默认帐户是
    git

    以防万一,请使用
    ssh -Tvvv git@<private_domain>.com
  • 再次测试

并确保您的密钥使用默认命名方案(如

~/.ssh/id_rsa[.pub]


1
投票

我通过删除

~/.ssh/known_hosts
中的行解决了这个问题。 删除与该地址相关的所有主机或IP。

www.####.com,xx.xx.xxx.xxx
10.15.##.## ssh-rsa AAAAB3NzaC1yc2EA

0
投票

对于这个错误 ssh:连接到主机203.0.113.0端口22:连接超时 我跟着这个 网站:https://medium.com/@manprajapat/cant-access-ssh-after-enable-ufw-in-ec2-aws-koffee-with-kode-5e481a5631c6


-1
投票

如果您使用的是在自定义域上运行的 gitlab,您可以执行以下操作

  • 通过执行 ssh-add 将您的 git 私钥添加到本地计算机上的 ssh-agent
  • 将以下配置文件添加到当前用户主目录。 (~/.ssh/config,相应更新参数)

Host gitlab
    HostName mycustomgitlabdomain.com
    User my-git-user
    IdentityFile ~/.ssh/my_private_key



进一步检查以下内容

  • 您可以使用任何用户在远程服务器上执行 SSH 吗?
  • 检查防火墙规则,是否有任何阻止
  • 用IP地址替换域名检查访问情况
  • 检查远程服务器的 SSH 端口(可能的 SSH 服务可能配置为在不同端口上运行)
© www.soinside.com 2019 - 2024. All rights reserved.