github - 将 www.github.com 添加到 known_hosts 文件的安全/正确方法是什么?

标签 github ssh openssh

我想通过 ssh 访问我的 github 存储库。当我第一次访问存储库时,系统会询问我是否要将 github ssh 服务器添加到我的 known_hosts文件,工作正常。该请求还向我显示了该服务器的 RSA key 指纹,我可以手动验证它与 github here 提供的相同。 .

These are the SHA256 hashes shown in OpenSSH 6.8 and newer (in base64 format):


SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 (RSA)
SHA256:br9IjFspm1vxR3iA35FWE+4VTyz1hYVLIE2t1/CeyWQ (DSA)

问题是我想通过添加公钥来阻止该请求
给我的known_hosts在我第一次访问我的 git 存储库之前的文件。这可以通过使用 ssh-keyscan -t rsa www.github.com 来完成。该命令将为我提供 known_hosts 所需格式的公钥文件。但是人们反复提到,这不安全,容易受到中间人攻击。他们没有提到的是如何正确地做。

那么如何使用github页面上提供的RSA指纹安全获取ssh服务器的主机公钥呢?我或多或少在寻找 ssh-keyscan 的选项该命令允许我添加预期的 rsa 指纹,并在主机指纹与给定指纹不匹配时导致命令失败。

感谢您的时间!

最佳答案

在这种情况下,我不会使用 ssh-keyscan。
相反,我会使用它并通过将其指纹与 GitHub 提供的指纹进行比较来仔细检查结果。

然后继续 SSH GitHub test ,检查我确实得到:

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

所以,as recommended here ,对于手动过程:
ssh-keyscan github.com >> githubKey

生成指纹:
ssh-keygen -lf githubKey

与 GitHub 提供的对比一下

最后复制githubKey内容到您的~/.ssh/known_hosts文件。

您可以使用 wercker/step-add-to-known_hosts 自动执行该过程(仍然包括指纹步骤检查)。 : 这是一个 wercker step , 但可以外推为它自己的独立脚本。
- add-to-known_hosts:
    hostname: github.com
    fingerprint: 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
    type: rsa

但这将缺乏对 help.github.com/articles/github-s-ssh-key-fingerprints 的检查。 : 见下文。

使用 nmap 没有多大帮助,因为 explained here :

using nmap to get the SSH host key fingerprint and then comparing it to what ssh-keyscan says the fingerprint: In both cases, the fingerprint comes from the same place.
It's just as vulnerable to MITM as any other of these automated solutions.

The only secure and valid way to verify an SSH public key is over some trusted out-of-band channel. (Or set up some kind of key-signing infrastructure.)



在这里, help.github.com/articles/github-s-ssh-key-fingerprints 仍然是“受信任的带外 channel ”。

关于github - 将 www.github.com 添加到 known_hosts 文件的安全/正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49670321/

相关文章:

Git-archive 远程端挂了

python - 如何将文件中的每一行作为参数传递给脚本?

使用 SSH 的 Git 提交请求电子邮件

android - 为 Android 构建 OpenSSH

openssh - 如何为除几个用户之外的每个用户禁用密码验证

eclipse - 推送到github存储库时需要错误401授权

bash - 找到本地 git 分支的远程父分支

xcode - 如何使用Swift Package Manager从 repo 中排除文件/文件夹?

java - 从云外的 JAVA 代码连接到 Openshift Online 3

perl - 使用Net::OpenSSH和Solaris SSH客户端的“Bad configuration option: ServerAliveInterval”