Capistrano bitbucket – 权限被拒绝(publickey)

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

这不是我第一次使用Capistrano在DigitalOcean上配置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-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密钥添加到身份validation代理:

 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(不需要部署的服务器来检出文件,但可能会更慢。)