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

ssh/known_hosts: No such file or directory

所以我在设置 GitLab 的过程中遇到了一个问题。即,https://docs.gitlab.com/ee/user/gitlab_com/index.html#ssh-host-keys-fingerprints 此 link 要求将条目添加到 known_hosts。然而,问题是,当我尝试 运行 一个像 /.ssh$ .ssh/known_hosts gitlab.com ssh-ed25519 ... 这样的命令时,我得到了这个错误。

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

apparently I don't even have that file in the first place. Is there a way to create it?

它将在您第一次 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 says in ,你应该在回答'yes'之前提前获取服务器实际指纹,并将该指纹与添加到~/.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