【问题标题】:Capistrano bitbucket - Permission denied (publickey)Capistrano bitbucket - 权限被拒绝(公钥)
【发布时间】:2013-08-26 02:32:03
【问题描述】:

我正在尝试使用 Capistrano 将我的应用程序部署到我的 DigitalOcean 服务器。

这不是我第一次在 DigitalOcean 上使用 Capistrano 部署配置 RoR 服务器,这就是我感到困惑的原因;我的工作流程中没有任何更改。

这是我的 Capistrano 配置文件:

require 'bundler/capistrano'
require 'rvm/capistrano'

set :application, "foobar"
set :repository,  "git@bitbucket.org:sergiotapia/foobar.git"
set :ping_url, "http://192.168.1.1/"
set :scm, :git
set :scm_verbose, true
default_run_options[:pty] = true

set :user, "sergiotapia" # The user on the VPS server.
set :password, "hunter2"
set :use_sudo, false
set :deploy_to, "/home/sergiotapia/www/#{application}"
set :deploy_via, :remote_cache
set :keep_releases, 1
set :rails_env, "production"
set :migrate_target, :latest

role :web, "192.168.1.1"
role :app, "192.168.1.1"

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, roles: :app, except: { no_release: true } do
    run "sudo touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

# Add this to add the `deploy:ping` task:
namespace :deploy do
  task :ping do
    system "curl --silent #{fetch(:ping_url)}"
  end
end

namespace :gems do
  task :bundle, :roles => :app do
    run "cd #{release_path} && bundle install --without development && rake db:migrate RAILS_ENV=production"
  end
end

after "deploy:update_code", "gems:bundle"

# Add this to automatically ping the server after a restart:
after "deploy:restart", "deploy:ping"

当运行 cap deploy:setupcap deploy:check 时,一切都会返回绿灯(工作正常)。

它在实际的cap deploy 命令上失败。

** [192.168.1.1 :: out] Enter passphrase for key '/home/sergiotapia/.ssh/id_rsa':
Password: 
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] Permission denied (publickey).
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] fatal: Could not read from remote repository.
** [192.168.1.1 :: out]
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] Please make sure you have the correct access rights
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] and the repository exists.
** [192.168.1.1 :: out]

我已经将我的 id_rsa.pub 文件添加到 BitBucket 中,并确保使用 ssh-add -l 命令将其添加到我的 SSH 代理中。

即使从远程服务器测试 SSH 也可以正常工作:

sergiotapia@tappia:~/www$ ssh -T git@bitbucket.org
logged in as sergiotapia.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

那么,为什么拒绝我访问 BitBucket 上的存储库?

Capistrano 是否以 sergiotapia 以外的用户身份运行?会是这个原因吗?

【问题讨论】:

  • 我也有这个问题!但是,我发现如果我的 ssh 密钥没有密码,我可以根据需要进行部署。 (对于某些机器来说,这是一个可以接受的解决方案。)
  • 从 Window 部署 Laravel 应用程序时遇到同样的问题。在 OSX 上运行良好。

标签: ruby-on-rails deployment capistrano bitbucket


【解决方案1】:

确保将您的 ssh 密钥添加到身份验证代理:

ssh-add ~/.ssh/id_rsa

并确保在 deploy.rb 中

ssh_options[:forward_agent] = true

编辑: 如果您在重新启动时丢失了 ssh-add 配置,您应该执行以下操作:

从 macOS Sierra 10.12.2 开始,Apple 添加了一个名为 UseKeychain 的 ssh_config 选项,它允许“正确”解决问题。将以下内容添加到您的 ~/.ssh/config 文件中:

Host *
   AddKeysToAgent yes
   UseKeychain yes 

【讨论】:

  • 在当前版本中我们应该在 deploy.rb 中添加 set :ssh_options, { forward_agent: true }
【解决方案2】:
  1. 您可以在 :app 服务器上设置 SSH 代理,
  2. 在 :app 服务器和 bitbucket 之间设置不需要密码的密钥。
  3. 将 deploy_via 更改为: :deploy_via, :copy (部署的服务器不需要签出文件,但可能会更慢。)

【讨论】:

  • @electrawn,我们遇到了同样的问题。是否需要实施所有这些步骤来解决问题?或者只需第 1 步或第 2 步就足够了。
猜你喜欢
  • 1970-01-01
  • 2018-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 2019-10-22
  • 2013-12-13
相关资源
最近更新 更多