2015-10-20 61 views
2

當我嘗試使用本地計算機(MAC){Rails應用}中的capistrano gem部署到服務器時,我得到以下內容。我是新來的軌使用capistrano進行分段的Rails部署會生成以下錯誤

user-mbp:xp user$ cap staging deploy 
Server password: 
******** 
DEBUG [c6110f69] Running /usr/bin/env [ -d ~/.rbenv ] as [email protected] 
DEBUG [c6110f69] Command: [ -d ~/.rbenv ] 
DEBUG [c6110f69] Finished in 6.956 seconds with exit status 0 (successful). 
INFO [e385c416] Running /usr/bin/env mkdir -p /tmp/pepe/ as [email protected] 
DEBUG [e385c416] Command: (RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env mkdir -p /tmp/pepe/) 
INFO [e385c416] Finished in 0.098 seconds with exit status 0 (successful). 
DEBUG Uploading /tmp/pepe/git-ssh.sh 0.0% 
INFO Uploading /tmp/pepe/git-ssh.sh 100.0% 
INFO [191046c4] Running /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh as [email protected] 
DEBUG [191046c4] Command: (RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh)`enter code here` 
INFO [191046c4] Finished in 0.119 seconds with exit status 0 (successful). 
INFO [bd99c2fc] Running /usr/bin/env git ls-remote --heads ssh://[email protected]/xp.git as [email protected] 
DEBUG [bd99c2fc] Command: (RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/pepe/git-ssh.sh /usr/bin/env git ls-remote --heads ssh://[email protected]/xp.git) 
DEBUG [bd99c2fc] Permission denied (publickey,password). 
DEBUG [bd99c2fc] fatal: The remote end hung up unexpectedly 
(Backtrace restricted to imported tasks) 
cap aborted! 
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: git exit status: 128 
git stdout: Nothing written 
git stderr: Permission denied (publickey,password). 
fatal: The remote end hung up unexpectedly 

SSHKit::Command::Failed: git exit status: 128 
git stdout: Nothing written 
git stderr: Permission denied (publickey,password). 
fatal: The remote end hung up unexpectedly 

我試過git:check,但仍顯示相同。

Tasks: TOP => git:check 
(See full trace by running task with --trace) 
The deploy has failed with an error: Exception while executing as [email protected]: git exit status: 128 
git stdout: Nothing written 
git stderr: Permission denied (publickey,password). 
fatal: The remote end hung up unexpectedly 

Staging.rb

# *************************************************************** # 
require 'highline' 

set :stage, :staging 

set :password, HighLine.new.ask('Server password:') { |q| q.echo = '*'} 
server 'xx.x.com', user: 'deployer', password: fetch(:password), roles: %w{web app db}, primary: true 
set :test_url, 'https://xx.x.com' 
set :version, `git describe --always` 

# you can set custom ssh options 
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options 
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) 
# set it globally 
# set :ssh_options, { 
# keys: %w(/home/rlisowski/.ssh/id_rsa), 
# forward_agent: false, 
# auth_methods: %w(password) 
# } 
# and/or per server 
# server 'example.com', 
# user: 'user_name', 
# roles: %w{web app}, 
# ssh_options: { 
#  user: 'user_name', # overrides user setting above 
#  keys: %w(/home/user_name/.ssh/id_rsa), 
#  forward_agent: false, 
#  auth_methods: %w(publickey password) 
#  # password: 'please use keys' 
# } 
# setting per server overrides global ssh_options 

# fetch(:default_env).merge!(rails_env: :staging) 
+0

我假設你從顯影機部署。從你的開發機器,你也推動混帳。這意味着你的開發機器上有你的git證書。您可以在將'set:ssh_options,:forward_agent => true'添加到config/deploy/staging.rb時轉發這些內容。如果這不起作用,那麼你可以發佈你的staging.rb文件。 – sugaryourcoffee

+0

hi @sugaryourcoffee發佈了staging.rb文件 –

+0

您是否檢查知識庫中的公鑰是否與您的部署機器上的私鑰相匹配?錯誤表明情況並非如此。如果你在Github上,那麼你可以從你的部署機器上檢查你是否可以用'ssh -vT git @ github.com'來訪問你的倉庫。 – sugaryourcoffee

回答

1

有兩種可能的解決方案

  1. 私鑰複製到部署機器 正如你可以推到Github上(這是我的理解)你的開發機器上有一個私鑰和Github上相應的公鑰。您可以將您的私鑰

    develeopment機$ SCP的〜/ .ssh/id-rsa.pub部署機複製到您的部署機器擺脫錯誤的:關鍵

然後ssh來部署的機器,並做

deployment-machine$ mv ~/.ssh/id-rsa.pub ~/.ssh/id-rsa.old 
deployment-machine$ mv ~/key ~/.ssh/id-rsa.pub 
  • 部署的機器上創建密鑰,並添加公鑰到Github上 有一個易於遵循的解釋如何做到這一點的Github Help
  • 希望這有助於。

    鏈接到項目中使用Capistrano的

    如果你是on Rails的3:

    如果你是on Rails的4:

    +0

    我認爲錯誤的原因是我的本地計算機指向我承諾並推送的特定git,而服務器(生產和分期)都是指向另一個git repo.i使用git remote -v命令檢查它。我該如何解決它? –

    +0

    在您的暫存配置文件中將存儲庫設置爲您將代碼推送到像'set:repository,'[email protected]:git_user/git_application.git'' – sugaryourcoffee

    +0

    仍然存在相同問題的存儲庫。我處於危機中stuff.Is有什麼辦法來解決這個問題,並從我的本地機器部署到登臺服務器 –

    相關問題