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 git@bitbucket.org: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:
ssh -T git@bitbucket.org
and the same exact git command manually without issue.What am I missing?
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 }