Rails Capistrano 身份验证失败错误

Rails Capistrano Authentication failed error

我正在尝试使用 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}

现在我尝试 fiddle 使用 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)
#   }

您应该在您的服务器上生成一个 SSH 密钥对。然后,将 public 密钥作为部署 ket 添加到 bitbucket 中的 git 存储库。之后,您应该可以在不输入密码的情况下下载 git 存储库

部署密钥通常用于自动部署,当您绝对必须将密钥留在服务器上时,以防万一它遭到破坏 - 其他人也可以访问您的存储库。

另外一种验证服务器访问的方法git是使用ssh代理转发,这种方式在这方面比较安全

运行 ssh-add 将您当前的 ssh 密钥添加到代理会话并重试,capistrano 也应该启用 ssh 代理转发,在 3 中它是默认启用的,但以防万一:

set :ssh_options, { forward_agent: true }