Rails Capistrano身份验证失败错误

时间:2015-12-02 21:34:19

标签: ruby-on-rails capistrano

我正在尝试使用Capistrano 3.4部署我的Rails 4应用程序,但不断获得身份验证失败错误。我只是不明白我应该在哪里设置Git仓库的密码。

运行命令cap production deploy --trace时出现错误消息:

** Execute git:check
INFO [d5512476] Running /usr/bin/env git ls-remote --heads https://xxx@bitbucket.org/xxx/myapp.git as xxx@162.242.219.184
DEBUG [d5512476] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/xxx/git-ssh.sh /usr/bin/env git ls-remote --heads https://xxx@bitbucket.org/xxx/myapp.git )
DEBUG [d5512476]        fatal: Authentication failed
DEBUG [d5512476]
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as xxx@162.242.219.184: git exit status: 128
git stdout: fatal: Authentication failed
git stderr: Nothing written
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
SSHKit::Command::Failed: git exit status: 128
git stdout: fatal: Authentication failed
git stderr: Nothing written
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/command.rb:95:in `exit_status='
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:179:in `block in _execute'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/capistrano-3.4.0/lib/capistrano/git.rb:11:in `git'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/capistrano-3.4.0/lib/capistrano/git.rb:21:in `check'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/capistrano-3.4.0/lib/capistrano/tasks/git.rake:28:in `block (4 levels) in <top (required)>'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/backends/abstract.rb:85:in `with'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/capistrano-3.4.0/lib/capistrano/tasks/git.rake:27:in `block (3 levels) in <top (required)>'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/xxx/.rvm/gems/ruby-2.2.2/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => git:check
The deploy has failed with an error: Exception while executing as xxx@162.242.219.184: git exit status: 128
git stdout: fatal: Authentication failed
git stderr: Nothing written
** Invoke deploy:failed (first_time)
** Execute deploy:failed

deploy.rb

lock '3.4.0'

set :application, 'xxx'
set :repo_url, 'https://xxx@bitbucket.org/xxx/myapp.git'
set :deploy_to, 'home/xxx/Sites/myapp'
set :scm, :git
set :format, :pretty
set :pty, true

deploy/production.rb

server '123.45.678.90', user: 'xxx', roles: %w{web app}
role :app, %w{xxx@123.45.678.90}
role :web, %w{xxx@123.45.678.90}
role :db,  %w{xxx@123.45.678.90}

现在我试图摆弄production.rb中的参数,但我一直遇到语法错误。

# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
#  set :ssh_options, {
#    keys: %w(/home/rlisowski/.ssh/id_rsa),
#    forward_agent: false,
#    auth_methods: %w(password)
#  }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server '123.45.678.90',
#   user: 'defined_user',
#   roles: %w{web app},
#   password: 'mypassword'
#   ssh_options: {
#     user: 'user',
#     keys: %w(/home/user_name/.ssh/id_rsa),
#     forward_agent: false,
#     auth_methods: %w(publickey password)
#   }

2 个答案:

答案 0 :(得分:2)

您应该在服务器上生成SSH密钥对。然后,将公钥作为部署包添加到bitbucket中的git仓库。之后,您应该能够在不输入密码的情况下下载您的git仓库

答案 1 :(得分:0)

部署密钥通常用于自动部署,当您必须将密钥留在服务器上时,如果它被泄露 - 有人也可以访问您的仓库。

验证服务器访问git的其他方法是使用ssh代理转发,这种方式在这方面更安全。

运行ssh-add将当前的ssh密钥添加到代理会话并重试,同时capistrano应启用ssh代理转发,默认情况下启用3,但以防万一:

set :ssh_options, { forward_agent: true }