ssh/known_hosts: 没有那个文件或目录

时间:2021-07-11 02:27:36

标签: ubuntu ssh gitlab

所以我正在设置 GitLab,但在此过程中遇到了一个问题。即,https://docs.gitlab.com/ee/user/gitlab_com/index.html#ssh-host-keys-fingerprints 此链接要求向 known_hosts 添加条目。但是,问题是,当我尝试运行 /.ssh$ .ssh/known_hosts gitlab.com ssh-ed25519 ... 之类的命令时,我收到此错误。

我刚刚从头开始设置了这个 ssh 东西。

1 个答案:

答案 0 :(得分:0)

<块引用>

显然我一开始甚至没有那个文件。有没有办法创建它?

它会在您第一次调用 ssh 时为您创建

ssh -T git@gitlab.com

那我会触发一条消息:

The authenticity of host '111.222.333.444 (111.222.333.444)' can't be established.
RSA key fingerprint is f1:cf:58:ae:71:0b:c8:04:6f:34:a6:b2:e4:1e:0c:8b.
Are you sure you want to continue connecting (yes/no)? 

回答是将创建 ~/.ssh/known_hosts


正如 chepner 中的 the comments 所说,在回答“是”之前,您应该提前获取服务器的实际指纹,并将该指纹与添加到 ~/.ssh/known_hosts 的指纹进行比较。

参见例如“Securely add a host (e.g. GitHub) to the SSH known_hosts file”。

例如:github.comgive its server fingerprints:将其与 ssh-keyscan -t rsa github.com | ssh-keygen -lf - 进行比较。

C:\Users\vonc\git>ssh-keyscan -t rsa github.com | ssh-keygen -lf -
# github.com:22 SSH-2.0-babeld-4cec2db4
2048 SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 github.com (RSA)

如果匹配,则将其添加到您的 ~/.ssh/known_hosts