【问题标题】:Could not resolve hostname for GitLab无法解析 GitLab 的主机名
【发布时间】:2018-11-18 01:15:59
【问题描述】:

所以我刚刚创建了一个 GitLab 项目并为 windows 安装了 Git,在生成/设置我的 ssh 密钥后,测试不成功:

C:\DiscordBot\SillyBot> ssh -vvvT git@Random-nii-chan
OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
debug3: Failed to open file:C:\\Users\\Random-nii-chan/.ssh/config error:2
debug3: Failed to open file:C:\\ProgramData\\ssh/ssh_config error:2
debug2: resolving "random-nii-chan" port 22
C:\\WINDOWS\\System32\\OpenSSH\\ssh.exe: Could not resolve hostname random-nii-chan: Unknown host.

我去了我的 git 文件夹,创建了一个 .ssh 目录并在其中生成了我的密钥(公共和私人)。

我做错了什么?

提前致谢!

【问题讨论】:

    标签: shell ssh gitlab host


    【解决方案1】:

    感谢您的帮助。正如你所说,我在 %USERPROFILE% 的 .ssh 文件夹中创建了 conf 文件,但是当我运行测试命令时,它说:

    C:\DiscordBot\SillyBot>ssh -vvvT git@Random-nii-chan
    OpenSSH_for_Windows_7.6p1, LibreSSL 2.6.4
    debug1: Reading configuration data C:\\Users\\Random-nii-chan/.ssh/config
    debug1: C:\\Users\\Random-nii-chan/.ssh/config line 1: Applying options for Random-nii-chan
    debug3: Failed to open file:C:\\ProgramData\\ssh/ssh_config error:2
    debug2: resolving "git@random-nii-chan" port 22
    ssh: Could not resolve hostname git@random-nii-chan: Une erreur irr\351cup\351rable s\222est produite lors d\222une recherche sur la base de donn\351es.
    

    (浏览数据库时出现无法获取的错误,如果翻译不正确,请见谅)

    这是我的配置文件的内容:

    Host Random-nii-chan
        Hostname git@Random-nii-chan
        User git
        IdentityFile C:\DiscordBot\SillyBot\.ssh\gitlab
    

    我用 nano 命令编辑了它

    【讨论】:

    • 主机名应该是真实的主机名
    • 为什么使用 git@,当我在我的回答中说你不必这样做时?
    【解决方案2】:

    首先,ssh 不会在“您的 git 文件夹”中查找您的密钥,而是在 %USERPROFILE% 中查找您的密钥 C:\Users\Random-nii-chan

    其次,确保您有一个 C:\Users\Random-nii-chan.ssh\config 文件(无扩展名,行尾为 LF,而不是 CRLF),您可以在其中定义什么是 random-nii-chan:

    Host random-nii-chan
       Hostname yourGitLabserver.com
       User git
       IdentityFile c:/path/to/your/private/key
    

    那你可以试试ssh -Tv random-nii-chan(不用加git@:用户在config文件中指定)

    【讨论】:

      猜你喜欢
      • 2016-12-30
      • 2018-10-23
      • 2020-01-30
      • 2017-03-26
      • 1970-01-01
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多