ruby-on-rails - 部署 Rails 应用程序时,Capistrano 3 的 SSH 代理转发不起作用

标签 ruby-on-rails ruby-on-rails-4 ssh capistrano capistrano3

我的deploy.rb中有以下设置

set :application, 'sample_app'
set :repo_url, '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a1a7b1a694e5e6e7fae0e1fae2e3fae5e4e4" rel="noreferrer noopener nofollow">[email protected]</a>:/home/user/railsapps/sample_app'
set :deploy_to, '/var/www/sample_app'
set :user, "user"
set :ssh_options, { :forward_agent => true }

和我的部署/生产.rb 文件:

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

当我运行 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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c494f594e7c0d0e0f120809120a0b120e0c0c" rel="noreferrer noopener nofollow">[email protected]</a>: 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.

在其中一行中,我看到它尝试以 [email protected] 的形式访问存储库。 ,这是生产服务器的部署用户:

INFO [] Running /usr/bin/env git ls-remote --heads <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f386809681b3c2c1c0ddc7c6ddc5c4ddc2c3c3" rel="noreferrer noopener nofollow">[email protected]</a>:/home/user/railsapps/sample_app as <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3b6b0a6b183f2f1f0edf7f6edf5f4edf1f3f3" rel="noreferrer noopener nofollow">[email protected]</a>

难道不应该说它是以本地用户身份使用本地 ssh key 进行连接吗? Capistrano 是否登录到生产服务器,然后从存储库中提取代码?如果是,有没有办法让它将代码从存储库推送到生产服务器?

最佳答案

您的 Git URL 似乎无效。您可以通过连接到远程系统 ( <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bfef8eef9cbbab9b8a5bfbea5bdbca5b9bbbb" rel="noreferrer noopener nofollow">[email protected]</a> ) 来测试这一点,并尝试使用简单的 git ls-remote --heads 访问远程 Git 存储库。这将证明连接性。

git ls-remote --heads <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e5b5d4b5c6e1f1c1d001a1b001819001f1e1e" rel="noreferrer noopener nofollow">[email protected]</a>:/home/user/railsapps/sample_app

我怀疑您可能需要.git附加到您的 URL ( <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0b5b3a5b280f1f2f3eef4f5eef6f7eef1f0f0" rel="noreferrer noopener nofollow">[email protected]</a>:/home/user/railsapps/sample_app.git ),但这实际上取决于您如何设置远程存储库。

Git 确实使用 SSH 进行连接,但它没有在 Capistrano 输出中明确显示这一点。您将看到的只是明确的 git命令。

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

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 才能按预期工作。

您可以查看这篇文章“Using ssh-agent with ssh”来帮助进行 SSH 配置。

关于ruby-on-rails - 部署 Rails 应用程序时,Capistrano 3 的 SSH 代理转发不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36900222/

相关文章:

mysql - Thinking-sphinx 返回不符合标准的结果

ruby-on-rails - VScode ERB 和 HTML 格式化程序不能一起工作

ruby-on-rails - 根据 Rails 中的 has_many 关系计数选择流行模型

ssh - gitolite 如何将远程用户映射到存储库用户?

python - "type object ' EllipticCurvePublicKey ' has no attribute ' from_encoded_point '"在 pysftp/Paramiko 中

ssh - EC2 : how to bundle an ssh private key into a private AMI?

ruby-on-rails - 无法安装 sqlite3 并运行捆绑安装

ruby-on-rails - 嵌套形式: shouldn't save if no information for child is entered

ruby-on-rails - 如何清除 Rails 文件缓存?

activerecord - 导轨 4 : Export database to YAML