Reputation: 3935
I am not able to clone my repository to my remote EC2 ubuntu instance using my deployment key. Here are the steps I followed.
~/.ssh/know_hosts
following https://stackoverflow.com/a/26520681/808734Here is the output of ssh -T [email protected]
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 protected]
But when I try to clone the repository
sudo git clone [email protected]: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.
Upvotes: 3
Views: 3555
Reputation: 188
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://[email protected]:team_name/repo_name.git
to
ssh://[email protected]/team_name/repo_name.git
Upvotes: 0
Reputation: 3935
Well this is embarrassing, the problem here was I was running the command as sudo
user.
sudo git clone [email protected]: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 [email protected]
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
Upvotes: 11