Capistrano 3部署:致命:无法从远程存储库读取

问题描述 投票:0回答:2

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

我能够将代码推送到git存储库以及从那里将其拉出来。

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

00:02 git:check
      01 git ls-remote [email protected]: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存储库的Settings,“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.),部署过程失败。

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

ruby-on-rails git ssh capistrano capistrano3
2个回答
1
投票

看起来您的SSH密钥未被转发。通常这是因为您的SSH密钥不可用于ssh-agent进行转发。 Github有a good writeup on this,但你可能只需要运行:ssh-add project_name

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

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


0
投票

希望您在存储库中正确添加ssh密钥。我认为您使用HTTPS(如git clone https://[email protected]/appname.git)克隆存储库,因为bitbucket是一个私有存储库,用qsh替换https,如git clone https://[email protected]/appname.git,请记住在您的Droplet中创建ssh密钥时不要添加密码,把它留空。希望这对未来铁路爱好者有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.