user984621
user984621

Reputation: 48443

Capistrano 3 deploy: fatal: Could not read from remote repository

I have a Rails 5 and Capistrano 3 app.

I am able to push the code to the git repository as well as to pull it over from there.

However, when I try to deploy the code to the (DigitalOcean) server via Capistrano, I get this error message:

00:02 git:check
      01 git ls-remote [email protected]:username/reponame.git HEAD
      01 repository access denied.
      01 fatal: Could not read from remote repository.
      01
      01 Please make sure you have the correct access rights
      01 and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@IP: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Tasks: TOP => deploy:check => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer@IP: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


** DEPLOY FAILED

What I have done: I have a generated a new SSH key on my mac, the output is in the files called project_name and project_name.pub. Then I have ran this command:

cat ~/.ssh/project_name.pub | pbcopy

and pasted this key code to the Settings of the Bitbucket repository, section "SSH keys".

In the Capistrano config file, I have the following:

set :ssh_options, {
  keys: %w(/Users/my_name/.ssh/project_name),
  forward_agent: true,
  auth_methods: %w(publickey password),
  port: 22
}

When I run cap production deploy, I am being asked to enter the password and afterward, the deployment process fails due the error mentioned above (Please make sure you have the correct access rights and the repository exists.).

How to propertly set the keys/fix the deployment issue?

Upvotes: 2

Views: 1801

Answers (2)

Abhishek Aravindan
Abhishek Aravindan

Reputation: 1482

Hope you add the ssh key correctly in your repository.I think you are cloning the repository using HTTPS like git clone https://[email protected]/appname.git as bitbucket is a private repository replace https with ssh like git clone https://[email protected]/appname.git and please do remember not to add passphrase when creating ssh key in your droplet,leave it blank.Hope this help for future rails enthusiasts.

Upvotes: 0

angrybit
angrybit

Reputation: 31

Looks like your SSH key isn't being forwarded. Typically this is because your SSH key isn't available to ssh-agent for forwarding. Github has a good writeup on this, but you probably just need to run: ssh-add project_name.

You may also need to change your SSH config, which the Github article gets into, but I'd start with just the ssh-add.

Note, my assumption based on your forward agent: true, is that you're trying to deploy by forwarding your local SSH key to Github, not using a deploy key that exists on the app server. If that's not the case and your deploy key is on the server, just set that to false.

Upvotes: 3

Related Questions