簡體   English   中英

Capistrano bitbucket - 權限被拒絕(publickey)

[英]Capistrano bitbucket - Permission denied (publickey)

我正在嘗試使用Capistrano將我的應用程序部署到我的DigitalOcean服務器上。

這不是我第一次在DigitalOcean上配置RoR服務器而Capistrano部署了這就是為什么我感到困惑; 我的工作流程沒有改變任何內容。

這是我的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-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密鑰添加到身份驗證代理:

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 
  1. 您可以在:app服務器上設置SSH代理,
  2. 設置密鑰,不需要在:app server和bitbucket之間使用密碼。
  3. 將deploy_via更改為:: deploy_via,:copy(不需要部署的服務器來檢出文件,但可能會更慢。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM