Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying to Digital Ocean from Bitbucket - Permission denied (publickey) error

I'm trying to deploy my Rails app from Bitbucket to Digital Ocean. I'm using Git as my version control system, I have done the following:

  1. grab my computers ssh key pbcopy < ~/.ssh/id_rsa.pub
  2. add my computers ssh key to Digital Ocean (https://cloud.digitalocean.com/ssh_keys)
  3. add my computers ssh key to Bitbucket repo as a deployment key (https://bitbucket.org/<account name>/<project admin/deploy-keys)

but when I run the cap deploy it gives this error

    servers: [<server ip>]
    [<server ip>] executing command
 ** [<server ip> :: out] Permission denied (publickey).
 ** [<server ip> :: out]
 ** [<server ip> :: out] fatal: Could not read from remote repository.
 ** [<server ip> :: out]
 ** [<server ip> :: out]
 ** [<server ip> :: out] Please make sure you have the correct access rights
 ** [<server ip> :: out]
 ** [<server ip> :: out] and the repository exists.
 ** [<server ip> :: out]

Here is my deploy.rb file

set :scm, "git"
set :repository, "[email protected]:<user name>/<project name>.git"
set :branch, "master"

If I clone the repo to my local, it works fine. I went through the Bitbucket docs, but still cannot figure out what is missing.

And my ssh to Bitbucket works:

ssh -T [email protected]
authenticated via a deploy key.


You can use git or hg to connect to Bitbucket. Shell access is disabled.

This deploy key has read access to the following repositories:

<repor name>

Found this SO question but without any luck.

like image 1000
sameera207 Avatar asked Aug 11 '14 13:08

sameera207


1 Answers

OK, I found the solution, I will add it here so that someone might find it useful.

I fixed the problem my creating a SSH key in Digital Ocean and adding it to Bitbucket.

Following are the steps

  • create a SSH key in Digital Ocean
  • add that SSH key as a Digital Ocean SSH key
  • add the same key to Bitbucket deployment key (https://bitbucket.org/<user>/<project>/admin/deploy-keys)
like image 84
sameera207 Avatar answered Sep 21 '22 22:09

sameera207