如何在部署应用时解决权限被拒绝?

时间:2014-08-04 13:41:25

标签: capistrano digital-ocean

我已经设置了一个应用程序来部署到我的站点,该站点托管在Digital Ocean CentOS 6服务器上,我正在使用Capistrano从我的开发机器部署应用程序。我有一个我推送的repo设置,当我cap development deploy时,我的Capistrano配置引用。

我遇到的问题是它会抛出此错误:

[a7406f5e] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/PopupHub/git-ssh.sh /usr/bin/env git ls-remote git@repo-url-is-here/popup-hub.git )
DEBUG [a7406f5e]    Permission denied (publickey).
DEBUG [a7406f5e]    fatal: The remote end hung up unexpectedly

在capfile中我得到了这个:

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'


# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/sitemap_generator'

# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

在我的config / deploy.rb中,我有:

lock '3.1.0'
server "0.0.0.0.0"

set :application, "NameOfApp"
set :scm, "git"
set :repo_url, "git@the-repo-url-is-here/popup-hub.git"
# set :scm_passphrase, ""

# set :user, "deploy"

# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml}

# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

SSHKit.config.command_map[:rake]  = "bundle exec rake" #8
SSHKit.config.command_map[:rails] = "bundle exec rails"

set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"


set :keep_releases, 20

namespace :deploy do
  desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
  task :restart do
    on roles(:app) do
      execute :touch, release_path.join('tmp/restart.txt')

      unless execute :curl, '-s -k --location localhost | grep "Pop" > /dev/null'
        exit 1
      end
    end
  end
  after :finishing, "deploy:cleanup"
  after :finishing, "deploy:sitemap:refresh"
end

after "deploy", "deploy:migrate"
after 'deploy:publishing', 'deploy:restart'

# deploy:sitemap:create   #Create sitemaps without pinging search engines
# deploy:sitemap:refresh  #Create sitemaps and ping search engines
# deploy:sitemap:clean    #Clean up sitemaps in the sitemap path
# start new deploy.rb stuff for the beanstalk repo

然后在我的config / development.rb中我得到了:

set :stage, :development

set :ssh_options, {
    forward_agent: true,
    password: 'thepassword',
    user: 'deployer',
}

server "0.0.0.0", user: "deployer", roles: %w{web app db}
set :deploy_to, "/home/deployer/development"

set :rails_env, 'development'                  # If the environment differs from the stage name

set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"

当我推入bash cap development deploy时,错误会进一步发生。

谁能告诉我为什么会这样?到目前为止,我已经完成了一切,我在另一个数字海洋液滴上安装了这个设置。

谢谢,

2 个答案:

答案 0 :(得分:2)

我认为您没有使用本地系统的ssh密钥访问远程服务器。

如果您在本地系统上没有ssh密钥,请生成:

ssh-keygen -t rsa

将您的本地密钥上传到远程服务器:

cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'

来源:HowToGeek.com

答案 1 :(得分:1)