【问题标题】:Can't access AWS CodeCommit with SSH无法使用 SSH 访问 AWS CodeCommit
【发布时间】:2016-01-03 19:26:36
【问题描述】:

很难弄清楚如何让 AWS CodeCommit 与标准 SSH 身份验证一起工作。看到另一个这样的话题,但没有答案,我还不允许发表评论。这是在 Windows 上使用 Git Bash。

重现步骤

  1. 已创建具有完全权限的 IAM 用户 (AwsAdministrator)
  2. 来自 ~/.ssh 中的 Git Bash
  3. “cat id_rsa.pub”并将输出复制到剪贴板
  4. 在 IAM 控制台中,单击按钮添加 SSH 密钥并粘贴到输入字段中。点击保存。
  5. 尝试访问 CodeCommit 存储库(在这种情况下尝试推送)并获得“权限被拒绝”。

Git + SSH 输出

这是我从带有 DEBUG3 日志记录的 SSH 中得到的:

debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/Dan/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug2: input_userauth_pk_ok: fp SHA256:<omitted>
debug3: sign_and_send_pubkey: RSA SHA256:<same-as-above>
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
fatal: Could not read from remote repository.

为了比较,这是我使用与 GitHub 完全相同的 SSH 密钥得到的结果:

debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/Dan/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug2: input_userauth_pk_ok: fp SHA256:<same-as-above>
debug3: sign_and_send_pubkey: RSA SHA256:<same-as-above>
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.252.130]:22).

以上输出来自于运行一个普通的 git 命令,例如 git push origin master,并在 .ssh/config 中启用了 ssh 调试日志记录:

Host git-codecommit.us-east-1.amazonaws.com
  LogLevel DEBUG3

Host github.com
  LogLevel DEBUG3

【问题讨论】:

  • 您用来获取此日志的命令是什么?您可以在服务器错误日志中看到什么?
  • @Jakuje 用我如何运行命令来获取日志更新了描述。不知道如何查看 AWS 和 GitHub 的服务器日志?

标签: git ssh aws-codecommit


【解决方案1】:

您似乎错过了设置 SSH 的步骤。您需要将此信息添加到您的 .ssh/config 文件中:

Host git-codecommit.us-east-1.amazonaws.com
   User Your-SSH-Key-ID, such as APKAEIBAERJR2EXAMPLE
   IdentityFile Your-Private-Key-File, such as ~/.ssh/codecommit_rsa or ~/.ssh/id_rsa

您可以从 IAM 控制台获取 Your-SSH-Key-ID。

【讨论】:

  • 确实是这个问题,谢谢!如果我查看 Linux/Mac steps here 而不是尝试翻译 Windows steps here 会更加明显
  • 我依赖于由 sourcetree 创建的配置文件,但它不起作用。一旦我将我的配置文件更改为此它就可以工作了
【解决方案2】:

我的情况有点不同。

“安全凭证”选项卡同时具有“访问密钥”和“AWS CodeCommit 的 SSH 密钥”。确保您使用的是 CodeCommit 密钥 ID。

【讨论】:

    【解决方案3】:

    这有效

    Host git-codecommit.us-west-2.amazonaws.com
        User SSHKEYID
        IdentityFile ~/.ssh/id_rsa
    

    【讨论】:

      【解决方案4】:

      制作git clone时尽量使用sshkey-ID

      所以 git clone 应该是这样的:

      git clone ssh://<SSHKEY-ID>@git-codecommit.<REGION>.amazonaws.com/v1/repos/<REPO-NAME>
      

      【讨论】:

        【解决方案5】:

        确保配置文件没有保存为txt文件并使用SSH Key ID,而不是Access

        【讨论】:

          【解决方案6】:

          请遵循 AWS 提供的以下文档

          Linux

          https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-unixes.html
          

          Windows

          https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-windows.html

          我只测试了windows的ssh连接,请按照上面提到的链接测试linux的ssh连接;

          以下是在 Windows 10 上为 codecommit 设置 SSH 连接的步骤。

          第 1 步

          CodeCommit 的初始配置(请参考文档链接)

          第 2 步

          安装 Git(请参考文档链接)

          第 3 步

          通过运行以下命令生成 ssh 密钥:

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

          运行此命令后,它应该在 C:\Users{user name here}.ssh 目录中生成公钥(.pub)和私钥

          第 4 步

          登录到 aws 管理控制台并转到 IAM-->用户 --> 选择目标用户 --> 安全凭证选项卡 -->AWS CodeCommit 的 SSH 密钥 并单击上传 ssh 密钥。复制粘贴公钥的内容,例如 C:\Users{此处的用户名}.ssh\id_rsa.pub 并保存更改。但是您可以在使用命令时为您的公钥(id_rsa.pub)选择不同的名称ssh-keygen -t rsa -b 4096 -C "your_email@example.com".

          第 5 步:

          上传公钥后,复制 SSH 密钥 ID。

          第 6 步

          在此处创建 C:\Users{用户名}.ssh\config 文件(没有文件扩展名,在 Windows 中将其保存为 config 并选择所有文件类型选项。Config.txt 很可能不起作用)。 将以下内容粘贴到 C:\Users{此处的用户名}.ssh\config 文件中:

          Host git-codecommit.*.amazonaws.com
            User {copy SSH key ID here}
            IdentityFile ~/.ssh/{copy name of the public key here }
            
          Host git-codecommit.*.amazonaws.com
            User THISISEXMAPLE123
            IdentityFile ~/.ssh/id_rsa
            
          

          第 7 步

            git clone ssh://Your-SSH-Key-ID@git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo my-demo-repo
          

          【讨论】:

            【解决方案7】:

            AWS 核心配置的变化各不相同。您可能会正确完成所有配置,但连接仍然存在问题。直截了当。

            尝试将默认的 git url 来源从旧更改为 @git-codecomitxxxxxxxx/v1/repos/xxxxx 确保密钥服务作为存储库的用户所有者

            然后再推。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2016-02-17
              • 2017-02-15
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2018-02-09
              相关资源
              最近更新 更多