54

I've been using capistrano successfully for a while now and all of a sudden in every project I've lost the ability to deploy.

Environment:

  • os X (Mavericks)
  • ruby 1.9.3p194
  • rvm (locally, not on server)
  • rails 3.2 and up
  • RubyGems 1.8.25

I'm not using rsa_keys or anything I want capistrano to prompt for user and password. Suddenly it has decided not to ask for a password, but does ask for user. Then it rolls back and gives me the following error.

[deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: sub.example.com (Net::SSH::AuthenticationFailed: Authentication failed for user user@sub.example.com)
connection failed for: sub.example.com (Net::SSH::AuthenticationFailed: Authentication failed for user user@sub.example.com)

This has occurred on my personal laptop and my iMac at work. It occurs when deploying to two different servers (both linux)

I'm completely at a loss here. Any ideas?

Sparkmasterflex
  • 1,837
  • 1
  • 20
  • 33
  • did you try to login ssh manually? – Chen Feb 04 '14 at 21:30
  • yes, that works in every case – Sparkmasterflex Feb 04 '14 at 23:12
  • 7
    See also this net-ssh issue, where the problem is currently being discussed: https://github.com/net-ssh/net-ssh/issues/145 – Zach Lipton Feb 11 '14 at 19:02
  • Is this issue for Capistrano 2 or 3? For Capistrano 3 I believe the README for "Using password authentication" says: set :password, ask('Server password', nil) server 'server.domain.com', user: 'ssh_user_name', port: 22, password: fetch(:password), roles: %w{web app db} It's very uncomfortable to fill the password this way instead of prompting like it was before :( – Renato Silva Das Neves May 23 '14 at 16:37
  • Setting :password does not resolve this issue in Capistrano 2 with anything after net-ssh 2.7, I would suspect this is an issue for Capistrano 3 as well. – Omn Jan 03 '15 at 02:58

9 Answers9

95

Figured it out! Apparently this issue was with net-ssh gem. I had version 2.8.0 installed recently with some updates to my development environment and was the cause.

I'm not sure why it was failing, but gem uninstall net-ssh -v 2.8.0< fixed it for me.

If anyone actually knows why this was an issue or how I can correct this issue with the newer version of net-ssh I'd be interested to hear it.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Sparkmasterflex
  • 1,837
  • 1
  • 20
  • 33
  • 4
    Anyone else who runs into this should be aware that locking net-ssh at 2.7.0 and net-ssh-gateway at 1.2.0 worked for me. – Momer Feb 10 '14 at 20:59
  • After remove, i have a error: Could not find 'net-ssh' (>= 2.0.14) among 14 total gem(s) (Gem::LoadError) – ZhukV Feb 13 '14 at 18:12
  • 7
    After you uninstall net-ssh 2.8.0, make sure you have another version installed to satisfy other gems dependencies, like 2.7.0 – aruanoc Feb 18 '14 at 23:05
  • 1
    So for instance run `gem install net-ssh -v 2.7` – jcroll Mar 19 '14 at 14:34
  • 6
    I added `gem 'net-ssh', '~>2.7.0'` next to `gem 'capistrano', '~>2.15.5'` in my Gemfile and ran `bundle update` afterwards. – Fabian Winkler Apr 01 '14 at 18:24
  • Your gut instinct to uninstall Net-SSH version 2.8.0 is good. But the problem is if there isn’t another lower-number version to use, things will break. Such a scenario can come form someone who just installed Net-SSH recently without any other version present. The best version to solve this issue is Net-SSH version 2.7.0 and that should be installed after version 2.8.0 is uninstalled. Now when is 2.8.1 going live already to fix this? – Giacomo1968 Apr 12 '14 at 00:07
  • Where is the `Gemfile` located on a Mac? – kaizenCoder Apr 22 '14 at 10:30
  • Your Gemfile is located in the root of your Rails App. If you're using Capistrano outside of a rails app then you'll just need to handle this w/o bundler gem uninstall ... – Sparkmasterflex May 01 '14 at 14:23
  • This is still a problem through net-ssh 2.9.1 butnet-ssh 2.9.2 (when it is released) does prompt for password again. It doesn't however, use capistrano's :password parameter. That still only works in 2.7 – Omn Jan 03 '15 at 02:07
18

The answer may break your rails app due to gem dependancies.

The issue is with net-ssh as was correctly answered by Sparkmasterflex, however whilst this will get capistrano working ok it may break your rails app:

These steps fixed both capistrano and rails for me ...

  1. In your Gemfile add gem 'net-ssh', '2.7.0'
  2. Run bundle update net-ssh
  3. Run bundle (just to be sure everything is working ok'
  4. Run gem uninstall net-ssh -v 2.8.0

If you are a rails user you should now be able to run both the rails server and capistrano.

Community
  • 1
  • 1
creativetechnologist
  • 1,452
  • 13
  • 29
  • I followed the steps and it printed "Using net-ssh 2.7.0", but I still got error: ruby-2.1.2/lib/ruby/2.1.0/rubygems/dependency.rb:298:in `to_specs': Could not find 'net-ssh' (>= 2.8.0) - did find: [net-ssh-2.7.0] (Gem::LoadError) – aqingsao Oct 22 '14 at 14:27
12

I have a workaround that doesn't require downgrading net-ssh, per a comment at the link that Zach Lipton posted. Place this code in config/deploy.rb:

set :ssh_options, {
  config: false
  #Other options...
}

After I did that, I got another error, Error reading response length from authentication socket. Found the solution to that here. Execute these commands at your Bash prompt:

$ eval $(ssh-agent)
$ ssh-add
Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
8

Upgrading your net-ssh version to 2.8.1 will solve the problem. They released a version bump in 19th february 2014 that fix this and other problems.

  1. Uninstall your current net-ssh gem (gem install net-ssh -v 'version')
  2. Just paste this on your Gemfile:

    gem 'net-ssh', '~> 2.8.1', :git => "https://github.com/net-ssh/net-ssh"

  3. Run bundle install

  • 2
    Yet, it was net-ssh-2.9.1 that broke this for me. So, if they fixed it in 2.8.1, they broke it again. Reverting to an older version fixed it. – juanitogan Nov 24 '14 at 16:59
8

I had the same problem while deploying using capistrano Net::SSH::AuthenticationFailed: Authentication failed for user deployer@IP

ssh-copy-id deployer@ip

This will add your keys to server and you can login without password.

Anbazhagan p
  • 943
  • 1
  • 14
  • 27
3
set :ssh_options, {
 verbose: :debug
}

... helps a lot!

I had an issue that I generated my public and private keys with puttygen and exported private key as OpenSSH with name <somename>.id_rsa. An then saved public key with name <somename>.id_rsa.pub.

( ! ) The public key puttygen saves is in RFC 4716 format not PEM. Use public suffix instead of pub for public key file-

vellotis
  • 829
  • 1
  • 12
  • 26
1

This snippet works for me:

group :development do
  #.....
  gem 'capistrano', "~> 2.15"
  gem "net-ssh", "~> 2.7.0"
  #.....
end
Muntasim
  • 6,689
  • 3
  • 46
  • 69
1

First try to connect to your server with certificate (file.pem) with this command:

ssh -i "file.pem" user@yourServerIp

Then try to run cap production deploy. It solved error for me. I think it is because time limit for certificate expired.

Boomerange
  • 616
  • 1
  • 10
  • 18
0

If all the above solutions doesn't work,please restart your system as you might be facing the issue due to net-ssh host connections.when you restart and enter the deployment command ,it will ask to add the identity to known hosts.

Jaswinder
  • 1,455
  • 14
  • 27