0

I am trying to deploy my rails application (Ruby 2.1.2 and Rails 4.1.4) through capistrano from mac. I have ssh keys set up on server. But i keep getting authentication error whenever i try to deploy. The error is:

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

followed by:

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

This is my 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"

I am able to login to server via terminal using ssh [email protected] but cannot login with capistrano. Any help or advice will be appericiated.

1

2 Answers 2

1

At first. You use two different users in one config. Choice one and edit your staging.rb

Also I am not sure that using public key is a good way. Try to add private key for user Deploy. Then if you able to login as deploy

ssh -i id_rsa [email protected]

try to update gem net-ssh to version 3.0.1. Then you can write your config like

set :ssh_options, {
  user: "deploy",      
  keys: ["~/.ssh/id_rsa"]      
} 
Sign up to request clarification or add additional context in comments.

Comments

0

I have faced the same issue for my application https://www.wiki11.com.

Those who are getting error

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

Here is the solution,

First of all you need to ssh to your server and run

eval `ssh-agent`

and then

ssh-add ~/.ssh/id_rsa

and now change

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

to

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

I just removed pub from id_rsa.pub.

And then run

cap production deploy:initial

It should work now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.