Search code examples
rubydeploymentcapistrano

Capistrano login Net::SSH failure


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, "[email protected]: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!


Solution

  • 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!