3

I am not able to clone my repository to my remote EC2 ubuntu instance using my deployment key. Here are the steps I followed.

  1. I deleted the existing deployment keys I had in my bitbucket account
  2. I cleaned ~/.ssh/know_hosts following https://stackoverflow.com/a/26520681/808734
  3. I generated my new key following these steps and added it as a deployment key to the repo.
  4. Here is the output of ssh -T git@bitbucket.org

    You can use git or hg to connect to Bitbucket. Shell access is disabled. This deploy key has read access to the following repositories: username/repository: KEYNAME -- email@gmail.com

  5. But when I try to clone the repository
    sudo git clone git@bitbucket.org:username/repository.git I get the following error Cloning into 'repository'... Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

Am I missing something here? Anybody has any advice?

Thanks for reading.

Community
  • 1
  • 1
akotian
  • 3,885
  • 1
  • 33
  • 44

2 Answers2

10

Well this is embarrassing, the problem here was I was running the command as sudo user.

sudo git clone git@bitbucket.org:username/repository.git 

This probably was attempting to clone repository as root user and causing the error. However cloning as the current user, and providing write permissions to the required directory let me clone the repository successfully.

Also during the process my ssh key seemed to have gotten reset, so ensure that ssh -T git@bitbucket.org works as expected. If not, running

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add ~/.ssh/id_rsa

worked for me. more details

akotian
  • 3,885
  • 1
  • 33
  • 44
  • 1
    `ssh-add` saved me. Even after I had created a new key and tried that one, I had to manually add it with `ssh-add`. Well done! – Aarmora May 27 '16 at 17:27
  • Woah! that did it!, If not a problem could you please tell what was the real issue and what did this code do ? – BlackBurn027 Sep 14 '17 at 14:25
0

If you are part of the team and trying to clone the repository then you may need to change the url a bit i.e.

from

ssh://git@bitbucket.org:team_name/repo_name.git

to

ssh://git@bitbucket.org/team_name/repo_name.git

rizTaak
  • 188
  • 1
  • 12