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 deploy@xxx.xxx
followed by:
Net::SSH::AuthenticationFailed: Authentication failed for user deploy@xxx.xx
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 root@xxx.xx
but cannot login with capistrano. Any help or advice will be appericiated.
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 deploy@xxx.xx.xx.xx
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"]
}
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 deploy@XXX.XX.XX.XXX
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.