I’ve been trying to clone a private git repository from BitBucket and getting the response:
$ git clone firstname.lastname@example.org:my/repo.git
Cloning into ‘repo’…
Permission denied (publickey).
fatal: Could not read from remote repository.
There are two things that need to be done to fix this.
Add your SSH Key to BitBucket
Firstly, make sure your git server has your SSH key. I’m using BitBucket so as per their documentation:
ssh-keygen cat ~/.ssh/id_rsa.pub
Copy and add your key to Settings – SSH Keys area in BitBucket.
Add your Key to the SSH Agent
If this still isn’t enough to fix the above error you may need to add your new key to your machines SSH agent.
1 2 3 4 5
# Make sure SSH agent is running eval `ssh-agent -s` # Add your key to the agent ssh-add ~/.ssh/id_rsa