简体   繁体   English

使用 GIT SSH 连接 Amazon EC2 时权限被拒绝

[英]Permission denied while connecting Amazon EC2 with GIT trought SSH

I am using Amazon EC2 instance as dev server and I am trying to git clone my repository from bitbucket to amazon EC2 instance.我正在使用 Amazon EC2 实例作为开发服务器,并且我正在尝试将我的存储库从 bitbucket git clone 到 amazon EC2 实例。 What i like to do is to add post hook commit to bitbucket, so all changes committed to the repository automatically to reflect to my dev server.我喜欢做的是将 post hook commit 添加到 bitbucket,因此所有提交到存储库的更改都会自动反映到我的开发服务器。

I am connecting trough ssh to my Amazon EC2 instance, but when i try to git clone the repository i am getting following error:我正在通过 ssh 将 ssh 连接到我的 Amazon EC2 实例,但是当我尝试 git clone 存储库时,出现以下错误:

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I found many solutions about this problem but none of them seems to work!我找到了很多关于这个问题的解决方案,但它们似乎都不起作用!

Here is what i have tried so far:这是我迄今为止尝试过的:

-created elastic ip and associate with my instance -创建弹性IP并与我的实例关联

-modified the security group to allow inbound network traffic -修改安全组以允许入站网络流量

-download the generated pem key from amazon and generate private and public key using puttygen - 从亚马逊下载生成的 pem 密钥并使用 puttygen 生成私钥和公钥

-uploaded the public key (id_rsa.pub) and pem key to my .ssh folder and changed the permissions to 600 - 将公钥 (id_rsa.pub) 和 pem 密钥上传到我的 .ssh 文件夹并将权限更改为 600

-added the public key to bitbucket deployment keys - 将公钥添加到 bitbucket 部署密钥

-added the public key to the authorized_keys file on amazon - 将公钥添加到亚马逊上的authorized_keys 文件中

-created a config file inside .ssh folder and added following lines inside: - 在 .ssh 文件夹中创建了一个配置文件,并在其中添加了以下几行:

Host bitbucket.org
Hostname bitbucket.org
User ubuntu
IdentityFile ~/.ssh/amzon_key.pem

-tried to git clone the repository as root user - 尝试以 root 用户 git clone 存储库

I'm using putty on windows.我在窗户上使用腻子。

Solution by OP. OP的解决方案。

What I did to make it work:我做了什么使它工作:

-deleted the config file from .ssh folder - 从 .ssh 文件夹中删除了配置文件

-created new private and public keys using puttygen (dsa - 1024) - 使用 puttygen (dsa - 1024) 创建新的私钥和公钥

-added the public key to the bitbucket deployment keys - 将公钥添加到 bitbucket 部署密钥中

-added the public key to the amazon authorized_keys file in the .ssh folder - 将公钥添加到 .ssh 文件夹中的 amazon authorized_keys 文件中

-uploaded the keys to the .ssh folder and set permissions to 600 - 将密钥上传到 .ssh 文件夹并将权限设置为 600

-added bitbucket.org to the list of known_hosts file in the .ssh folder -将 bitbucket.org 添加到 .ssh 文件夹中的 known_hosts 文件列表

The key that we need to add here is the one that we have added in the bitbucket.我们需要在这里添加的key是我们在bitbucket中添加的key。 So the server has permission to access the bitbucket and perform the git commands.因此服务器有权访问 bitbucket 并执行 git 命令。 So change the identity file name with the name that you have added.因此,使用您添加的名称更改身份文件名。 As in the Question, it is id_rsa.在问题中,它是 id_rsa。

Host bitbucket.org
Hostname bitbucket.org
User ubuntu
IdentityFile ~/.ssh/id_rsa

This is a suggestion.这是一个建议。 Because I don't have enough reputation to comment.因为我没有足够的声誉来发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM