【问题标题】:Capistrano 3 deploy: fatal: Could not read from remote repositoryCapistrano 3 部署:致命:无法从远程存储库读取
【发布时间】:2018-03-06 07:29:30
【问题描述】:

我有一个 Rails 5 和 Capistrano 3 应用程序。

我可以将代码推送到 git 存储库,也可以从那里提取它。

但是,当我尝试通过 Capistrano 将代码部署到 (DigitalOcean) 服务器时,我收到以下错误消息:

00:02 git:check
      01 git ls-remote git@bitbucket.org:username/reponame.git HEAD
      01 repository access denied.
      01 fatal: Could not read from remote repository.
      01
      01 Please make sure you have the correct access rights
      01 and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@IP: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Tasks: TOP => deploy:check => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer@IP: git exit status: 128
git stdout: Nothing written
git stderr: repository access denied.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


** DEPLOY FAILED

我做了什么:我在我的 mac 上生成了一个新的 SSH 密钥,输出在名为 project_nameproject_name.pub 的文件中。然后我运行了这个命令:

cat ~/.ssh/project_name.pub | pbcopy

并将此密钥代码粘贴到 Bitbucket 存储库的“SSH 密钥”部分的设置中。

在 Capistrano 配置文件中,我有以下内容:

set :ssh_options, {
  keys: %w(/Users/my_name/.ssh/project_name),
  forward_agent: true,
  auth_methods: %w(publickey password),
  port: 22
}

当我运行cap production deploy 时,我被要求输入密码,然后由于上述错误(Please make sure you have the correct access rights and the repository exists.),部署过程失败。

如何正确设置密钥/修复部署问题?

【问题讨论】:

  • 您是否能够在没有 capistrano 的情况下从 Digital Ocean 机器读取存储库?因为事实上,是访问您的存储库而不是您的计算机的 Digital Ocean 机器。因此,您需要将服务器 SSH id 作为您的 bitbucket 存储库中的部署密钥。
  • 是的,当我登录DigitalOcean服务器并运行git clone ...时,存储库将成功克隆到服务器上。但如果我尝试通过 Capistrano 部署代码,则会失败。
  • 您在使用与 capistrano 相同的用户?

标签: ruby-on-rails git ssh capistrano capistrano3


【解决方案1】:

您的 SSH 密钥似乎没有被转发。通常这是因为 ssh-agent 无法使用您的 SSH 密钥进行转发。 Github 有a good writeup on this,但你可能只需要运行:ssh-add project_name

您可能还需要更改 Github 文章中涉及的 SSH 配置,但我会从 ssh-add 开始。

注意,我基于您的forward agent: true 的假设是,您尝试通过将本地 SSH 密钥转发到 Github 来进行部署,而不是使用应用服务器上存在的部署密钥。如果不是这种情况,并且您的部署密钥在服务器上,只需将其设置为 false。

【讨论】:

    【解决方案2】:

    希望您在存储库中正确添加 ssh 密钥。我认为您正在使用 HTTPS 克隆存储库,例如 git clone https://user@bitbucket.org/appname.git,因为 bitbucket 是一个私有存储库,将 https 替换为 ssh,例如 git clone https://user@bitbucket.org/appname.git,请记住不要添加密码短语在您的 Droplet 中创建 ssh 密钥,将其留空。希望对未来的 Rails 爱好者有所帮助。

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 2014-11-25
      • 2012-11-10
      • 2015-10-31
      • 2015-01-19
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多