2015-12-02 196 views
0

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

这里运行命令cap production deploy --trace当是我的错误信息:

** Execute git:check 
INFO [d5512476] Running /usr/bin/env git ls-remote --heads https://[email protected]/xxx/myapp.git as [email protected] 
DEBUG [d5512476] Command: (GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/xxx/git-ssh.sh /usr/bin/env git ls-remote --heads https://[email protected]/xxx/myapp.git) 
DEBUG [d5512476]  fatal: Authentication failed 
DEBUG [d5512476] 
cap aborted! 
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: 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 [email protected]: 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://[email protected]/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{[email protected]} 
role :web, %w{[email protected]} 
role :db, %w{[email protected]} 

现在我试图反复折腾中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

你应该产生一个您的服务器上的SSH密钥对。然后,将公钥作为部署添加到你的git仓库中。之后,你应该可以在不输入密码的情况下下载你的git仓库。 –

+1

访问本教程,我知道它是用于webfaction托管,但它也适用于其他服务器以及https://docs.webfaction.com/software/rails.html#deploying-a-ruby-on-rails-application- with-capistrano – mariowise

+0

@ joshua.paling这是解决方案。谢谢。如果你希望你可以发表你的评论作为答案,所以我可以标记为正确的。 – aishaq11

回答

2

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

0

部署密钥通常用于自动部署,当您绝对必须将密钥留在服务器上时,并且万一它被攻破 - 某人也可以访问您的回购。

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

运行ssh-add您当前SSH密钥添加到代理会话,然后再试一次,也Capistrano的应启用SSH代理转发,在3它是默认启用的,但以防万一:

set :ssh_options, { forward_agent: true }