2015-11-23 45 views
0

我想部署我的rails應用程序(Ruby 2.1.2 and Rails 4.1.4)通過capistrano從mac。我在服務器上設置了ssh密鑰。但是,每當我嘗試部署時,我都會收到身份驗證錯誤。錯誤是:Ssh身份驗證錯誤,同時部署使用capistrano

SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx: Authentication failed for user [email protected] 

依次爲:

Net::SSH::AuthenticationFailed: Authentication failed for user [email protected] 

這是我staging.rb:

server "xxx.xx.xxx", user: "deploy", roles: %w{web app db} 
set :ssh_options, { 
    user: "root", 
    forward_agent: false, 
    keys: '~/.ssh/id_rsa', 
    auth_methods: %w(publickey password) 
} 
set :branch, "master" 
set :rails_env, "staging" 

我能夠通過使用ssh [email protected]終端登錄到服務器,但無法登錄Capistrano的。任何幫助或建議都會被修改。

+0

用戶'deploy @ xxx.xx'認證失敗,而不是'root @ xxx.xx'。糾正'staging.rb'文件的第一行。 – Mareq

回答

1

起初。您在一個配置中使用兩個不同的用戶。選擇一個編輯你的staging.rb

另外我不確定使用公鑰是一個好方法。嘗試爲用戶部署添加私鑰。然後如果你能夠部署登錄

shh -i id_rsa [email protected] 

嘗試更新gem net-ssh到版本3.0.1。然後你可以寫你的配置像

set :ssh_options, { 
    user: "deploy",  
    keys: ["~/.ssh/id_rsa"]  
} 
0

我面臨同樣的問題我的應用https://www.wiki11.com

這些誰收到錯誤

Net::SSH::AuthenticationFailed: Authentication failed for user [email protected] 

這裏是解決

所有你需要的ssh到你的服務器,並運行

eval `ssh-agent` 

,然後

第一
ssh-add ~/.ssh/id_rsa 

現在改變

set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) } 

set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa) } 

我剛剛從id_rsa.pub刪除pub

然後運行

cap production deploy:initial 

應該現在的工作。