Capistrano 3 - denied access to the git repository on the production server


I wanted to try the newer version of Capistrano 3 on a new project and have been struggling with this problem for a few days now.

while running "cap production deploy" for the first time, I always got the same error (LOG :

Apparently, it fails to run this command "git ls-remote [email protected]:......" on the server

I've tried everything : - forward_agent set as true with ssh key on local machine and uploaded on bitbucket - forward_agent set as false and uploaded manually the ssh key on the production server (when I run manually 'git [email protected]:......' on the server, it works perfectly.

I've already set the "user" attribute on the deploy.rb file, this doesn't fix the issue.

Thanks for the help, I'm open to any suggestion!

To those who has the same problem, my solution was to delete all the SSH keys from the ssh-agent (ssh-add -d path/to/all/keys) and then re-add your key (ssh-add yourkey).

I have no idea why but it seems that Capistrano 3 only consider the first key of your ssh-agent and use that key to access your git repository.

Hence, if your first key is not your project SSH key, then it will throw the exception error.

I didn't find any other way to fix it.