Capistrano login Net::SSH failure

2019-06-07 04:25发布

Suddenly, Capistrano began to return a SSH issue:

** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: staging.myserver.com (Net::SSH::AuthenticationFailed: root) connection failed for: staging.myserver.com (Net::SSH::AuthenticationFailed: root)

My deploy.rb contains:

require 'capistrano/ext/multistage'

ssh_options[:forward_agent] = true
ssh_options[:keys] = ["myserver_rsa"]

set :stages, ["staging", "production"]
set :default_stage, "staging"

set :scm, "git"
set :application, "myapp"
set :repository, "git@bitbucket.org:project/myapp.git"
set :use_sudo, false
set :deploy_via, :remote_cache

and at my config/deploy/staging.rb

server 'staging.myserver.com', :app, :web, :db, primary: true

set :branch, 'staging'
set :rails_env, "staging"

set :deploy_to, "/var/rails/#{application}"
set :user, "root"
set :password, "my_triple_check_password_login"
set :domain, "staging.myserver.com"

Tests made by me before posting here:

  1. Try to login via ssh (ssh -v staging.myserver.com) => Logged successfully without prompt my password. (using myserver_rsa key)

  2. Agent Forward => Enabled in server and in local

  3. Try to login via ssh without keys: => prompted for password. Copy and paste it from staging.rb and logged perfectly.

  4. Change server root password. => Try to login with new password via ssh root@... worked nice. but via capistrano, fails.

  5. Run in IRB a Net SSH script to login. => Logged in and return a hostname result from bash.

This issue starts yesterday suddenly. I really don't have more ideas :/

First of all, nothing was change at server either Cap deploy configs.

Thanks!

2条回答
叼着烟拽天下
2楼-- · 2019-06-07 05:06

This error is due to the authentication failure. Capistrano can't connect to the deploying server with given username and password. I already done the deployment for a server and I am now deploying to a New server. Then I got this error.

It prompted me to give the password for new server. I entered the new server password. But its showing this error.

I changed the domain here

set :domain, "my-new-ip-or-domain"   => my new server domain

But forgot to change the username here in my deploy.rb

set :user, "my-new-username"

After giving the correct username and password it works perfectly!

查看更多
Juvenile、少年°
3楼-- · 2019-06-07 05:15

I found!

In my /etc/ssh_config root section I had:

Host *
     SendEnv LANG LC_*
     XAuthLocation /opt/X11/bin/xauth
     ForwardAgent yes
     PasswordAuthentication yes

I was need to create a section to my staging environment:

   Host staging.myserver.com
     IdentityFile /Users/hlegius/.ssh/myserver_rsa
     ForwardAgent yes
     RSAAuthentication no
     PasswordAuthentication no

and edit my config/deploy.rb to add: default_run_options[:pty] = true

Aaaaaaaaand it's works!

查看更多
登录 后发表回答