【问题标题】:Error "The authenticity of host 'github.com' can't be established. RSA key fingerprint "错误“无法建立主机'github.com'的真实性。RSA密钥指纹”
【发布时间】:2018-05-22 07:40:10
【问题描述】:

我在工作中使用我的项目,但我想在家和他一起工作,因为我可以登录到我的家用机器来处理我的项目。

但是,我在家中看到以下消息:

The authenticity of host 'github.com (ip)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?

我怎样才能克服它?

【问题讨论】:

    标签: github fingerprint


    【解决方案1】:

    您应该只需回答“是”,这将更新您的~/.ssh/known_hosts 文件。


    避免任何MITM (Man-In-The-Middle) attack 的更好方法是(作为Mamsdscommented below)首先验证Github 的公钥(请参阅“GitHub's SSH key fingerprints”)并且,如果你找到匹配项,然后你可以回答“是”。


    之后,您可以使用 GitHub SSH URL(前提是您有 generated the SSH public/private keys,并在您的 GitHub 个人资料中注册了公共地址)

    注意:ssh 密钥生成应使用 base64 旧 PEM 格式(选项-m PEM),而不是当前新的 70 字符 OpenSSH 格式。
    见“What is the correct format for private key in Credentials”:

    ssh-keygen -m PEM -t rsa -P "" -f afile
    

    那个或者你可以switch to an HTTPS URL

    【讨论】:

    • 如果您只是回答“是”,我认为您应该添加有关 MITM 攻击的警告。更好的方法应该是首先验证 Github 的公钥(从这里:https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints),如果找到匹配项,则可以回答是。
    • @Mamsds 很好,谢谢。我已将您的评论包含在答案中以提高知名度。
    【解决方案2】:

    当您第一次尝试使用 SSH 连接到 Github 时(~/.ssh/known_hosts 中尚无 Github 条目),系统会要求您验证远程主机的密钥指纹。因为,如果入侵者主机将自己表示为 Github 服务器,它的 RSA 指纹将与 GitHub 服务器指纹不同。

    你有两个选择。

    1. 考虑到您不关心远程主机(在本例中为 Github)的真实性,您可以接受,或者,

    2. 您可以通过将您呈现给的 RSA 指纹(在提示中)与base64 格式的GitHub's SSH key fingerprints 匹配来验证您是否真正连接到 Github 服务器。

    后一种选择通常更可取。

    【讨论】:

      【解决方案3】:

      使用以下两种解决方案之一:

      1) 设置 SSH 密钥

      按照this GitHub 帮助页面上讨论的步骤进行操作。

      https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

      2) 使用带有 HTTPS 的 git 进行克隆

      在您要克隆存储库的机器上的终端中键入(复制/粘贴)以下命令

      git config --global url."https://github.com/".insteadOf git@github.com:
      git config --global url."https://".insteadOf git://
      

      您可以使用以下命令恢复此更改

      git config --global url."git@github.com:".insteadOf https://github.com/
      git config --global url."git://".insteadOf https://
      

      【讨论】:

      • 为什么是--global 而不是--local
      • 此外,此命令不会真正切换配置,但每次调用都会将一个附加到配置。
      【解决方案4】:

      试试这些步骤:

      打开 Git Bash

      检查现有的 SSH 密钥:

      $ ls -al ~/.ssh

      如果您已经拥有它们,您将看到:

      • id_rsa.pub
      • id_ecdsa.pub
      • id_ed25519.pub

      如果没有,请生成一个(按 Enter 接受默认文件位置):

      $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

      将密钥复制到剪贴板:

      $ clip < ~/.ssh/id_rsa.pub

      在 Github/Settings/SSH 和 GPG 密钥/新 SSH 密钥上转到您的帐户

      在此处粘贴您的密钥

      接下来,输入:

      $ git remote

      如果您看到原点,请将其删除:

      $ git remote remove origin

      继续执行 GitHub 存储库页面上提供的最后 2 个步骤...

      $ git remote add origin git@github.com:USERNAME/REPONAME.git

      $ git push -u origin master

      刷新您的 GitHub 存储库页面

      瞧!

      【讨论】:

      【解决方案5】:

      只需通过这种方式将 Github 指纹添加到已知主机:

      ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
      

      【讨论】:

      • 我也必须创建文件夹mkdir ~/.ssh
      猜你喜欢
      • 2022-12-06
      • 2021-02-13
      • 2016-08-09
      • 2022-08-12
      • 2013-09-13
      • 2011-04-09
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多