Capistrano SSH::AuthenticationFailed, not prompting for password
Ruby on-RailsRubyDeploymentCapistranoRuby on-Rails Problem Overview
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?
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
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.
Solution 2 - Ruby on-Rails
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 ...
- In your Gemfile add
gem 'net-ssh', '2.7.0'
- Run
bundle update net-ssh
- Run
bundle
(just to be sure everything is working ok' - 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.
Solution 3 - Ruby on-Rails
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
Solution 4 - Ruby on-Rails
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.
-
Uninstall your current net-ssh gem (gem install net-ssh -v 'version')
-
Just paste this on your Gemfile:
gem 'net-ssh', '~> 2.8.1', :git => "https://github.com/net-ssh/net-ssh"
-
Run bundle install
Solution 5 - Ruby on-Rails
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.
Solution 6 - Ruby on-Rails
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-
Solution 7 - Ruby on-Rails
This snippet works for me:
group :development do
#.....
gem 'capistrano', "~> 2.15"
gem "net-ssh", "~> 2.7.0"
#.....
end
Solution 8 - Ruby on-Rails
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.
Solution 9 - Ruby on-Rails
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.