Ruby ssh Net :: SSH :: AuthenticationFailed error when working with PHP

I'm trying to connect a server using SSH using Ruby, but I have a Net :: SSH :: AuthenticationFailed error. The problem is that it works in PHP.

Here's my ruby ​​code:

require 'rubygems'
require 'net/ssh'
include Net
domain = 'ks2.so.d-sites.com' # insert IP address or domain name here
begin
Net::SSH.start( domain, 'webistrano', :verbose => :debug, :keys => ['/home/webistrano/.ssh/id_rsa', '/home/webistrano/.ssh/id_rsa.pub'], :port => 22 ) do |ssh|
print "connected"
end
rescue Net::SSH::HostKeyMismatch => e
  puts "remembering new key: #{e.fingerprint}"
  e.remember_host!
  retry
end

      

And I am getting the following errors:

D, [2012-03-06T20:40:02.974862 #24165] DEBUG -- net.ssh.transport.session[3f8c5d3a06a0]: establishing connection to ks2.so.d-sites.com:22
D, [2012-03-06T20:40:02.975912 #24165] DEBUG -- net.ssh.transport.session[3f8c5d3a06a0]: connection established
I, [2012-03-06T20:40:02.976039 #24165]  INFO -- net.ssh.transport.server_version[3f8c5d39edc8]: negotiating protocol version
D, [2012-03-06T20:40:02.981160 #24165] DEBUG -- net.ssh.transport.server_version[3f8c5d39edc8]: remote is `SSH-2.0-OpenSSH_5.8p1-hpn13v10'
D, [2012-03-06T20:40:02.981231 #24165] DEBUG -- net.ssh.transport.server_version[3f8c5d39edc8]: local is `SSH-2.0-Ruby/Net::SSH_2.3.0 x86_64-linux'
D, [2012-03-06T20:40:02.982272 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: read 856 bytes
D, [2012-03-06T20:40:02.982418 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: received packet nr 0 type 20 len 852
I, [2012-03-06T20:40:02.982517 #24165]  INFO -- net.ssh.transport.algorithms[3f8c5d39e418]: got KEXINIT from server
I, [2012-03-06T20:40:02.982690 #24165]  INFO -- net.ssh.transport.algorithms[3f8c5d39e418]: sending KEXINIT
D, [2012-03-06T20:40:02.982883 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: queueing packet nr 0 type 20 len 716
D, [2012-03-06T20:40:02.982960 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: sent 720 bytes
I, [2012-03-06T20:40:02.983003 #24165]  INFO -- net.ssh.transport.algorithms[3f8c5d39e418]: negotiating algorithms
D, [2012-03-06T20:40:02.983161 #24165] DEBUG -- net.ssh.transport.algorithms[3f8c5d39e418]: negotiated:
* kex: diffie-hellman-group-exchange-sha1
* host_key: ssh-rsa
* encryption_server: aes128-cbc
* encryption_client: aes128-cbc
* hmac_client: hmac-sha1
* hmac_server: hmac-sha1
* compression_client: none
* compression_server: none
* language_client: 
* language_server: 
D, [2012-03-06T20:40:02.983207 #24165] DEBUG -- net.ssh.transport.algorithms[3f8c5d39e418]: exchanging keys
D, [2012-03-06T20:40:02.983416 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: queueing packet nr 1 type 34 len 20
D, [2012-03-06T20:40:02.983469 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: sent 24 bytes
D, [2012-03-06T20:40:03.024146 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: read 152 bytes
D, [2012-03-06T20:40:03.024270 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: received packet nr 1 type 31 len 148
D, [2012-03-06T20:40:03.027331 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: queueing packet nr 2 type 32 len 140
D, [2012-03-06T20:40:03.027409 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: sent 144 bytes
D, [2012-03-06T20:40:03.032446 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: read 720 bytes
D, [2012-03-06T20:40:03.032563 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: received packet nr 2 type 33 len 700
D, [2012-03-06T20:40:03.035433 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: queueing packet nr 3 type 21 len 20
D, [2012-03-06T20:40:03.035505 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: sent 24 bytes
D, [2012-03-06T20:40:03.035617 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: received packet nr 3 type 21 len 12
D, [2012-03-06T20:40:03.035954 #24165] DEBUG -- net.ssh.authentication.session[3f8c5e189fdc]: beginning authentication of `webistrano'
D, [2012-03-06T20:40:03.036081 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: queueing packet nr 4 type 5 len 28
D, [2012-03-06T20:40:03.036130 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: sent 52 bytes
D, [2012-03-06T20:40:03.074777 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: read 52 bytes
D, [2012-03-06T20:40:03.074912 #24165] DEBUG -- tcpsocket[3f8c5d39f250]: received packet nr 4 type 6 len 28
D, [2012-03-06T20:40:03.075018 #24165] DEBUG -- net.ssh.authentication.session[3f8c5e189fdc]: trying password
E, [2012-03-06T20:40:03.075077 #24165] ERROR -- net.ssh.authentication.session[3f8c5e189fdc]: all authorization methods failed (tried password)
/usr/lib64/ruby/gems/1.8/gems/net-ssh-2.3.0/lib/net/ssh.rb:200:in `start': webistrano (Net::SSH::AuthenticationFailed)
    from ssh-test.rb:6

      

I wrote some simple PHP code and it works:

<?php
$connection = ssh2_connect('ks2.so.d-sites.com', 22);

if (ssh2_auth_pubkey_file($connection, 'webistrano',
                          '/home/webistrano/.ssh/id_rsa.pub',
                          '/home/webistrano/.ssh/id_rsa')) {
  echo "Identification réussie en utilisant une clé publique\n";
} else {
  die('Echec de l\'identification en utilisant une clé publique');
}

      

Is there anyone who can help me? Thank you very much in advance!

+3


source to share


3 answers


I found how to solve this problem: by adding a parameter :auth_methods => ['publickey','password']

to the function Net::SSH.start

.



+4


source


I've seen this error before, try uninstalling the gem 'net-ssh', try this: gem uninstall net-ssh -v 2.8.0, it works for me, refer to: fooobar.com/questions/106732 / ...



+1


source


I have not used the Net :: SSH.start solution, but chose set :ssh_options, {:forward_agent => true, :auth_methods => 'publickey'}

which seems to work on my end.

It is noted that I initially used set: ssh_options {:forward_agent => true}

on three machines running FreeBSD, CentOS and MacOSX and it worked fine - even used in production releases, however after testing on a VOS beta based CentOS (6.4)) machine stopped working ... So adding auth_method did the trick.

0


source







All Articles