部署Rails应用程序时,Capistrano 3的SSH代理转发不起作用 [英] SSH agent forwarding with Capistrano 3 not working when deploying Rails app

查看:104
本文介绍了部署Rails应用程序时,Capistrano 3的SSH代理转发不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的deploy.rb中有以下设置。

I have the following setup in my deploy.rb

set :application, 'sample_app'
set :repo_url, 'user@123.45.67.100:/home/user/railsapps/sample_app'
set :deploy_to, '/var/www/sample_app'
set :user, "user"
set :ssh_options, { :forward_agent => true }

和我的deploy / production.rb文件:

and my deploy/production.rb file:

set :stage, :production
server '123.45.67.200', user: 'user', roles: %w{app db web}

运行上限生产部署时出现以下错误:check

I get the following error when I run cap production deploy:check

DEBUG [] ssh: connect to host 123.45.67.100 port 22: Connection timed out
DEBUG [] fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user@123.45.67.200: git exit status: 128
git stdout: Nothing written
git stderr: ssh: connect to host 123.45.67.200 port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

其中一行,我看到它尝试以user@123.45.67.200的身份访问存储库,这是生产服务器的部署用户:

In one of the lines, I see that it tries to access the repository as user@123.45.67.200, which is the deployment user for the production server:

INFO [] Running /usr/bin/env git ls-remote --heads user@123.45.67.100:/home/user/railsapps/sample_app as user@123.45.67.200

这不是说它正在使用本地ssh密钥作为本地用户进行连接吗? Capistrano是否登录到生产服务器,然后从存储库中提取代码?如果是,是否有办法将代码从存储库推送到生产服务器?

Shouldn't it be saying that it's connecting as the local user with the local ssh keys? Is Capistrano logging into the production server and then pulling code from the repository? If it is, is there a way to make it push code from the repository to the production server?

推荐答案

Git URL无效。您可以通过连接到远程系统( user@123.45.67.200 )进行测试,并尝试使用简单的 git ls-来访问远程Git存储库。远程--heads 这将证明其连通性。

It appears that your Git URL is not valid. You can test this by connecting to the remote system (user@123.45.67.200) and try to hit the remote Git repo with a simple git ls-remote --heads which will prove connectivity.

git ls-remote --heads user@123.45.67.100:/home/user/railsapps/sample_app

我怀疑您可能需要 .git 附加到您的URL( user@123.45.67.100:/home/user/railsapps/sample_app.git )后面,但这确实取决于有关如何设置远程仓库的信息。

I suspect that you might need .git appended to your URL (user@123.45.67.100:/home/user/railsapps/sample_app.git) but that really depends on how you have your remote repo set up.

Git确实使用SSH进行连接,但在Capistrano输出中并未明确显示。您将看到的是显式的 git 命令。

Git does use SSH to connect but it doesn't explicitly show that in the Capistrano output. All you will see are the explicit git commands.

或者,如果您希望使用代理转发,则您的ssh转发配置(本地或远程)可能会遇到问题。您可以通过检查本地计算机,然后连接到远程计算机并查看是否转发您的身份来进行测试。您可以这样操作:

Alternatively, if you are expecting to use agent forwarding then you might be experiencing an issue with your ssh forwarding config, either local or remote. You can test that by checking your local machine then connecting to a remote machine and seeing if your identity was forwarded. You would do that like this:

local-host$ ssh-add -l
local-host$ ssh user@remote-host
remote-host$ ssh-add -l

如果看到输出像这样:

Error connecting to agent: No such file or directory

或:

Could not open a connection to your authentication agent.

或:

The agent has no identities.

然后您需要先解决该问题,然后Capistrano才能按预期工作。

Then you need to sort out that issue before Capistrano will work as expected.

您可以检出此内容 将ssh-agent与ssh一起使用以帮助进行SSH配置。

You can checkout this write up "Using ssh-agent with ssh" to help with SSH config.

这篇关于部署Rails应用程序时,Capistrano 3的SSH代理转发不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆