[英]Rails Capistrano Authentication failed error
I am attempting to deploy my Rails 4 application using Capistrano 3.4, but continuously get an authentication failed error. 我正在尝试使用Capistrano 3.4部署我的Rails 4应用程序,但不断获得身份验证失败错误。 I just don't understand where I am supposed to set the password for the Git repo. 我只是不明白我应该在哪里设置Git repo的密码。
Here is my error message when running the command cap production deploy --trace
: 运行命令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}
Now I have tried to fiddle around with the parameters in production.rb
, but I keep getting syntax errors. 现在我试图摆弄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)
# }
You should generate an SSH key pair on your sever. 您应该在服务器上生成SSH密钥对。 Then, add the public key as a deploy ket to your git repo in bitbucket. 然后,将公钥作为部署包添加到bitbucket中的git仓库。 After that you should be able to download your git repo without entering a password 之后,您应该能够在不输入密码的情况下下载您的git仓库
Deploy keys are usually for automated deployments, when you absolutely have to leave the key on server, and in case it gets compromised - someone also can access your repo. 部署密钥通常用于自动部署,当您必须将密钥留在服务器上时,如果它被泄露 - 有人也可以访问您的仓库。
Other method to authenticate server to access git is to use ssh agent forwarding, this way is a bit safer in this respect. 验证服务器访问git的其他方法是使用ssh代理转发,这种方式在这方面有点安全。
Run ssh-add
to add your current ssh keys to agent session and try again, also capistrano should have ssh agent forwarding enabled, in 3 it's enabled by default, but just in case: 运行ssh-add
将当前的ssh密钥添加到代理会话并重试,同时capistrano应启用ssh代理转发,默认情况下启用3,但以防万一:
set :ssh_options, { forward_agent: true }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.