[英]Capistrano 3 deploy: fatal: Could not read from remote repository
I have a Rails 5 and Capistrano 3 app. 我有一个Rails 5和Capistrano 3应用程序。
I am able to push the code to the git repository as well as to pull it over from there. 我能够将代码推送到git存储库,也可以从那里拉过来。
However, when I try to deploy the code to the (DigitalOcean) server via Capistrano, I get this error message: 但是,当我尝试通过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
What I have done: I have a generated a new SSH key on my mac, the output is in the files called project_name
and project_name.pub
. 我做了什么:我在Mac上生成了一个新的SSH密钥,输出位于名为project_name
和project_name.pub
的文件中。 Then I have ran this command: 然后我运行了以下命令:
cat ~/.ssh/project_name.pub | pbcopy
and pasted this key code to the Settings of the Bitbucket repository, section "SSH keys". 并将此密钥代码粘贴到Bitbucket存储库的“设置”部分中。
In the Capistrano config file, I have the following: 在Capistrano配置文件中,我具有以下内容:
set :ssh_options, {
keys: %w(/Users/my_name/.ssh/project_name),
forward_agent: true,
auth_methods: %w(publickey password),
port: 22
}
When I run cap production deploy
, I am being asked to enter the password and afterward, the deployment process fails due the error mentioned above ( Please make sure you have the correct access rights and the repository exists.
). 当我运行cap production deploy
,系统会要求我输入密码,然后,由于上述错误,部署过程将失败( Please make sure you have the correct access rights and the repository exists.
)。
How to propertly set the keys/fix the deployment issue? 如何正确设置密钥/解决部署问题?
Looks like your SSH key isn't being forwarded. 看来您的SSH密钥没有被转发。 Typically this is because your SSH key isn't available to ssh-agent
for forwarding. 通常是因为您的SSH密钥不可用于ssh-agent
进行转发。 Github has a good writeup on this , but you probably just need to run: ssh-add project_name
. Github对此有很好的记录 ,但是您可能只需要运行: ssh-add project_name
。
You may also need to change your SSH config, which the Github article gets into, but I'd start with just the ssh-add
. 您可能还需要更改Github文章介绍的SSH配置,但我仅从ssh-add
。
Note, my assumption based on your forward agent: true
, is that you're trying to deploy by forwarding your local SSH key to Github, not using a deploy key that exists on the app server. 请注意,我基于您的forward agent: true
假设是,您正在尝试通过将本地SSH密钥转发到Github进行部署,而不使用应用程序服务器上存在的部署密钥。 If that's not the case and your deploy key is on the server, just set that to false. 如果不是这种情况,并且您的部署密钥在服务器上,则将其设置为false。
希望您在存储库中正确添加ssh密钥。我认为您正在使用git clone https://user@bitbucket.org/appname.git
类的HTTPS克隆存储库,因为bitbucket是私有存储库,请用git clone https://user@bitbucket.org/appname.git
ssh替换git clone https://user@bitbucket.org/appname.git
,请记住不要在小滴中创建ssh密钥时添加密码,请将其保留为空白。希望此帮助对将来的Rails爱好者有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.