Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

I am connecting trough ssh to my Amazon EC2 instance, but when i try to git clone the repository i am getting following error:

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

-modified the security group to allow inbound network traffic

-download the generated pem key from amazon and generate private and public key using puttygen

-uploaded the public key (id_rsa.pub) and pem key to my .ssh folder and changed the permissions to 600

-added the public key to bitbucket deployment keys

-added the public key to the authorized_keys file on amazon

-created a config file inside .ssh folder and added following lines inside:

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

-tried to git clone the repository as root user

I'm using putty on windows.

like image 841
Eagle Avatar asked Nov 10 '22 02:11

Eagle


1 Answers

Solution by OP.

What I did to make it work:

-deleted the config file from .ssh folder

-created new private and public keys using puttygen (dsa - 1024)

-added the public key to the bitbucket deployment keys

-added the public key to the amazon authorized_keys file in the .ssh folder

-uploaded the keys to the .ssh folder and set permissions to 600

-added bitbucket.org to the list of known_hosts file in the .ssh folder

like image 133
Cœur Avatar answered Nov 15 '22 04:11

Cœur