Git 克隆 EC2 实例权限错误

标签 git github amazon-ec2 ssh

我正在尝试将我的私有(private) github 存储库克隆到我的 EC2 实例,但看起来我可能采取了错误的步骤来允许 Github 连接到 EC2 实例。在我在路径 /var/www/app 创建的文件夹中运行 git clone git@github.com:username/repo.git 我被告知要验证 Githbuc .com 主机并提供​​两个 RSA key 指纹(我假设它们在我的 repo 中)然后向我发送一个错误:

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

Please make sure you have the correct access rights
and the repository exists.

在运行 git clone 命令之前,我将在我的 .pem 中找到的 SSH key 复制到我的 Github SSH key 中。这些 EC2 凭据是我用来通过 SSH 连接到实例的凭据。这是使用错误的 key 吗?我知道 EC2 实例也有在 .ssh/authorized_keys 中找到的公钥,但我觉得这些与用于通过 SSH 进入实例的公钥相同。

我错过了一步吗?我是否需要在我的 /var/www/app 目录中初始化 git 或在 git clone 命令之前配置任何东西?

任何帮助都会很棒。谢谢!

最佳答案

确保您在本地计算机上生成 ssh key 对 ~/.ssh/并且您的公钥已添加到您的 GitHub 帐户中。

要将 ssh key 对从本地目录克隆到 EC2 实例,请按照以下步骤操作:

将您的公钥克隆到您的 EC2 实例:

$ cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/your_pem.pem ubuntu@your_dns "cat >> .ssh/authorized_keys"

如果“.ssh/authorized_keys”不存在,请登录到您的 EC2 实例并创建目录:

$ ssh -i ~/.ssh/***.pem ubuntu@[Your Public DNS]
$ mkdir ~/.ssh
$ chmod 700 ~/.ssh
$ touch ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
$ exit  # exit EC2 terminal, this will not stop your instance

然后继续将我们的 GitHub 私钥安全地复制到 EC2 实例。 “UserKnownHostsFile”和“StrictHostKeyChecking”选项删除主机验证提示(计算机要求您键入是或否以继续)。如果我们想在脚本中运行这些操作,删除它是必不可少的。

$ scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/your_pem.pem ~/.ssh/id_rsa ubuntu@your_dns:~/.ssh/

您应该能够使用您的 ssh key 对连接到 git。

如果它没有修复,“使用 Amazon EC2 在 GitHub 存储库中运行脚本”的更完整教程:

https://github.com/yafangy/Tutorial-using-Amazon-AWS-EC2-run-scripts-GitHub/tree/master#method-2-clone-git-to-ec2-instance-recommended

关于Git 克隆 EC2 实例权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51380792/

相关文章:

linux - 通过 GPRS 部署到嵌入式设备

git - 如何使用 git bash 更改文件夹?

ios - 在 Swift 中使用 SPUserResizableView

c++ - 我可以在不创建自己的 Docker 镜像的情况下在 Gitpod 中加载其他库吗?

python - git 可以输出 "branch"和 "remotes/origin/branch"之间的提交数的最简单方法

git - 如何列出 git 存储库中跟踪文件的所有不同扩展名?

git - Git 分支的优点(对于 SVN 用户)

java - 尝试连接到 RDS 时 AWS EC2 间歇性 UnknownHostException

ruby-on-rails - 将 Ruby on Rails 项目从 github 上传到 AWS EC2 实例出错

wordpress - 为负载均衡器(EC2)创建多个实例的正确方法