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

BharteeSahareTechRoR
2 min readSep 6, 2023

The Problem: Deploying with Capistrano

Deploying Rails applications with Capistrano is a powerful and widely used process, but it’s not always without its challenges. One common issue that can arise is the error message:

The authenticity of host 'github.com (*.*.*.82)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,*.*.*.82' (ECDSA) to the list of known hosts.
git@github.com: Permission denied (publickey).


fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

Solution: Authentication in the Repo URL

One way to address this issue is to include your GitHub credentials directly in the repository URL in your deploy.rb file:

# I am able to fix this issue by replacing
# remove this
set :repo_url, 'git@github.com:ProjectName/current.git'
# add this
set :repo_url, 'https://my_github_username:my_github_password@github.com/ProjectName/current'

By doing this, you provide the necessary authentication directly in the URL, allowing Capistrano to access the repository without issues.

Lately, an alternative solution has gained popularity. Before executing the cap production deploy command, run the following commands in your terminal:

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

Happy deploying! 🚀 Please follow for more updates BharteeTechRoR

--

--

BharteeSahareTechRoR

Ruby on Rails Developer || React Js || Rspec || Node Js