无法通过 SSH 连接到自定义端口上的 Gitlab 容器

Unable to connect to Gitlab Container on Custom Port via SSH

  1. 我有一个 VMWare Player,它是 运行 一个本地 VM,它托管着 Gitlab 服务器,基于官方容器 repo。我已将端口更改如下:

    Host → Container
    27→22
    85→80

  2. 我可以从我的浏览器地址 http://192.168.71.129:85/ 访问 gitlab。

  3. 我使用 GitHub 的 Git PowerShell 添加了 SSH 密钥到我可以在本地访问的 Gitlab 帐户。

  4. 我在 .ssh 目录中创建了一个配置文件,其内容如下:

    #in gitlab.com server
    Host 192.168.71.129
    Port 27
    User git
    RSAAuthentication yes
    IdentityFile ~/.ssh/id_rsa
    
  5. 当我尝试使用 Gitlab 中所示的以下命令推送到我的 Gitlab 帐户时:

    cd existing_folder
    git init
    git remote add origin git@gitlabhost:someuser/secondtest.git
    git add .
    git commit
    git push -u origin master
    

我从上一条语句中得到以下错误:

ssh: Could not resolve hostname gitlabhost: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

我缺少什么设置?有什么提示、建议吗?

谢谢 Ansgar Wiechers,下面是我的 netstat 输出

$ netstat -l -t -n
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:9344          0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 :::8089                 :::*                    LISTEN
tcp        0      0 :::27                   :::*                    LISTEN
tcp        0      0 :::85                   :::*                    LISTEN
tcp        0      0 :::22                   :::*                    LISTEN

实际上,正如您指出的那样,问题出在名称解析上。我将命令更改为仅 IP 地址而不是主机名,我能够得到它。

C:\Users\SomeUser\Documents\FirstPhPProj> git init
Initialized empty Git repository in C:/Users/SomeUser/Documents/FirstPhPProj/.git/
C:\Users\SomeUser\Documents\FirstPhPProj [master +6 ~0 -0 !]> git remote add origin git@192.168.71.129:alamabbas/secondtest.git
C:\Users\SomeUser\Documents\FirstPhPProj [master +6 ~0 -0 !]> git add .

根据错误消息,无法解析主机名 gitlabhost

ssh: Could not resolve hostname gitlabhost: Name or service not known

您将服务器的 IP 地址放入 SSH 配置中:

Host 192.168.71.129

但在设置存储库来源时使用了主机名:

git remote add origin git@gitlabhost:someuser/secondtest.git

有两种方法可以解决这个问题:

  • 使用源站IP地址:

    git remote add origin git@192.168.71.129:someuser/secondtest.git
    
  • 确保正确的名称解析,例如通过在 /etc/hosts:

    中添加这样一行
    192.168.71.129    gitlabhost