Search code examples
gitsshcapistranobitbucketlinode

Why suddenly is Capistrano unable to read from my Bitbucket Git repository during deploy?


I use Capistrano (v3.5.0) to deploy a small Rails application from my local development machine to a VPS hosted on Linode using a deployment key set up on Bitbucket. As late as last week, it was working like a charm.

Today, however, when I run the usual cap deploy command, it fails at the third step when it tried to read from my Bitbucket Git repository:

DEBUG [6906a62c] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.2.1"
  GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/app/git-ssh.sh" ; /usr/bin/env git
  ls-remote --heads [email protected]:klenwell/app.git )

This is the error:

DEBUG [6906a62c]       conq: repository access denied.
DEBUG [6906a62c]       fatal: The remote end hung up unexpectedly

I've done the obvious troubleshooting: googled the errors messages, confirmed the VPS is operational, verified the repository is accessible, double-checked the SSH keys, confirmed the SSH agent is running. If all else fails, I will try generating a new key on my VPS host.

These points in particular have me flummoxed:

  • There have been (as far as I can tell) no changes to the Capistrano or VPS configuration since it last ran successfully. I see the same command running successfully in my Capistrano logs last week.
  • When I ssh into my VPS server as the deploy user, I can run ssh -T [email protected] and the same exact git command manually without issue.
  • The Jenkins server on my local machine can successfully read from the same Bitbucket repository using its deployment key.

What am I missing?


Solution

  • By default, Capistrano uses SSH agent forwarding. Effectively this means it will use your local SSH key for auth with BitBucket.

    Perhaps your local key changed or no longer has BitBucket access, which would explain why the deploy no longer works.

    You can disable Capistrano's SSH agent forwarding (thereby allowing Git to use the deployment key you have installed on the server) like this:

    set :ssh_options, { forward_agent: false }