3

I want to clone a repository to an EC2 instance I'm using. I generated ssh key pair using "ssh-keygen".

Your public key has been saved in /home/ubuntu/.ssh/id_rsa2.pub.

the id_rsa2.pub looks something like:

ssh-rsa a_very_long_sequence ubuntu@ip-a-b-c-d

I pasted the key as it is to the keys associated with my bit bucket account. But I'm being prompted

Invalid SSH key (ssh-keygen).
nish
  • 6,952
  • 18
  • 74
  • 128

2 Answers2

3

So what might be a problem is that you add your SSH-key as the ubuntu user, but you git clone the repository with sudo.

So what you need to do, if you use sudo git clone git@bitbucket.org:username/repo.git, you need to get the id_rsa.pub from the root user and add it to Bitbucket (or Git?):

sudo su - root  # switch to root user
cat ~/.ssh/id_rsa.pub  # create if not already existing
sudo su - ubuntu  # switch back to normal user

Now I can pull/clone from my repository without password authentication.

Özer
  • 2,059
  • 18
  • 22
2

.ssh/id_rsa2.pub isn't the default name an ssh session will look for to pass to the server.

Try and rename your keys in

.ssh/id_rsa
.ssh/id_rsa.pub 

Or use a ~/.ssh/config file to point to the right private/public keys.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250