【问题标题】:How to Clone from GitHub如何从 GitHub 克隆
【发布时间】:2015-01-05 07:30:11
【问题描述】:

我是使用 GitHub 的新手。我正在尝试从用户存储库中克隆我的第一个文件。 我不断收到此错误:

Permission denied (publickey). fatal: Could not read from remote repository

当我检查以验证公钥是否已附加到我的 GitHub 帐户时,使用以下命令:

ssh-add -1

我收到此错误: The agent has no identities.

我也试过这个: ssh-add ~/.ssh/id_rsa

它告诉我: Identity added

我还确保我的笔记本电脑的 SSH 密钥已添加到我的 GitHub 帐户。我错过了哪些步骤?

我已经扫描了互联网 - 我迷路了。

【问题讨论】:

    标签: github cloning


    【解决方案1】:

    或者,您可以使用 https 协议进行克隆,即https://github.com/Organization/repo.git,您不需要密钥对。

    【讨论】:

      【解决方案2】:

      尝试通过https链接git clone https://github.com/github_user_name/repository_name克隆存储库

      您可以手动将 SSH 密钥添加到您的 github 帐户中。

      1. 打印您的公共 SSH 密钥 cat ~/.ssh/id_rsa.pub
      2. 复制输出
      3. 转到您的 github 帐户设置。从个人设置中选择 SSH 密钥。
      4. 选择新的 SSH 密钥并粘贴 cat ~/.ssh/id_rsa.pub 的输出。您可以给出一些名称来记住计算机名称。

      【讨论】:

        【解决方案3】:

        您可以通过 2 种方式克隆 github 存储库。您可以在克隆存储库时选择类型。

        1. HTTPS

          git clone https://github.com/flyway/flyway.git

        如果是私有仓库,您可能需要提供用户名/密码。

        1. SSH

          git clone git@github.com:flyway/flyway.git

        您需要在您的 PC 中设置 ssh 密钥并在您的 github 帐户中更新。

        阅读更多关于

        Adding SSH Keys

        Which remote URL should I use?

        【讨论】:

          【解决方案4】:

          Oh-my-zsh 方法:

          如果使用 oh-my-zsh,您可以使用 ssh-agent 插件为您管理 SSH 连接。

          https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/ssh-agent

          1. 您需要编辑~/.zshrc
          2. ssh-agent 添加到您的插件列表 - 插件应该用空格分隔逗号 | 例如 plugins=(git ssh-agent)
          3. 添加agent-forwarding 并设置您的密钥身份,引用您的私钥。这些应添加到此行上方:source $ZSH/oh-my-zsh.sh | Reference
          4. $ source ~/.zshrc 重新加载您的 zshrc 配置文件
          5. 确认识别的密钥可用于 ssh-agent $ ssh-add -l

          如果您在~/.zshrc 文件中确定的密钥已经是added 到 github,您将能够通过 SSH 连接到 github。

          钥匙串方法:

          1. ssh-add ~/.ssh/PATH_TO_YOUR_SSH_PRIVATE_KEY(例如 ~/.ssh/id_rsa)
          2. ~/.ssh/config - $ open ~/.ssh/config 中添加以下内容
          Host * 
            AddKeysToAgent yes
            UseKeychain yes
            IdentityFile PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
          

          AddKeysToAgentUserKeychain 参数将确保密钥存储在钥匙串中并可供 ssh-agent 使用

          1. 重启你的终端

          2. 确认识别的密钥可用于 ssh-agent $ ssh-add -l

          如果您在 ~/.ssh/config 文件中确定的密钥是 added 到 github,您将能够通过 SSH 连接到 github。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2021-12-21
            • 2016-09-25
            • 2016-11-30
            • 2021-01-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多