Rails 4 + Capistrano 3 : fatal: Could not read from remote repository while deploying

Current Solution

Lately I use different solution. Before cap production deploy I run following commands.

  1. eval "$(ssh-agent -s)"
  2. ssh-add ~/.ssh/id_rsa

Previous Solution

I am able to fix this issue by replacing

set :repo_url, '[email protected]:BoTreeConsultingTeam/magnificent.git'

with

set :repo_url, 'https://my_github_username:[email protected]/BoTreeConsultingTeam/magnificent'

Note if your password contains special characters then thet should be url encoded. You can quickly encode using URI::encode in irb.

With other deployments using Capistrano 2, I never need to supply github credentials.

Can anybody please tell why should I have to specify git username/password in repo_url?

There is one more solution in the upcase forum post which also worked.


I had this problem too. Turns out I had loaded the wrong SSH key and it interfered with the deployment. Solved it by removing the wrong loaded ssh key like so:

ssh-add -d ~/.ssh/wrong-ssh-key

and then running the Capistrano deployment again.


This could also happen if you are deploying to the server for the first time, and the git server is not in the known host list of your deployment server.

so, logging into the remote server and then doing a git request to the repository will cause the git server to be added to the known host list.

like so:

git ls-remote [email protected]:your_gitbucket_user_id/your_repo.git master

The authenticity of host 'bitbucket.org (104.192.143.2)' can't be established.
RSA key fingerprint is SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojabwzha.
Are you sure you want to continue connecting (yes/no)? yes

you should confirm to connect.

Warning: Permanently added 'bitbucket.org,104.192.143.2' (RSA) to the list of known hosts.

Now try deploying using the capistrano task.

cap production deploy