sameera207
sameera207

Reputation: 16629

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.

Upvotes: 6

Views: 6498

Answers (2)

Suresh Sekar
Suresh Sekar

Reputation: 928

If you would like to add additional SSH keys to a droplet that already has some keys, you will need to enable password authentication over SSH to get this done. Adding a SSH key through the control panel can only be added to a droplet during its creation.

If you are unable to access the machines with existing SSH keys, you will need to follow these steps using the web console for your droplet. To enable password authentication, please follow the steps below.

Edit this configuration file with your favorite text editor.

/etc/ssh/sshd_config

Find the line that says "PasswordAuthentication no" and change it to "PasswordAuthentication yes" and then save and exit the editor.

Once back at your command prompt, run the following command to allow the new SSH changes to take place.

/etc/init.d/ssh restart

Once SSH has restarted, you can try SSH'ing to your droplet. If you are getting a permission denied error, you may need to update your password by using the "passwd" command.

When you are successfully logged into your server via SSH on your computer, I recommend following the steps in the article below to get a new SSH key configured for this droplet.

https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2

I hope this information is helpful! Please let us know if you have any questions or run into any problems along the way!

Upvotes: 0

sameera207
sameera207

Reputation: 16629

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)

Upvotes: 13

Related Questions