2012-03-06 2 views
3

Я пытаюсь подключить сервер, хотя SSH с помощью Ruby, но у меня есть ошибка Net :: SSH :: AuthenticationFailed. Проблема в том, что он работает в PHP.Ошибка Ruby ssh Net :: SSH :: AuthenticationFailed во время работы с PHP

Вот мой рубиновый код:

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 

И я получаю эту ошибку:

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 

Я написал простой PHP код, и она работает:

<?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'); 
} 

Есть ли кто-то что может мне помочь? Большое спасибо!

ответ

4

Я нашел, как решить эту проблему: добавив параметр :auth_methods => ['publickey','password'] в функцию Net::SSH.start.

+0

проверки также ': non_interactive => true' – nhed

0

Я не использовал решение Net :: SSH.start, но выбрал set :ssh_options, {:forward_agent => true, :auth_methods => 'publickey'}, который, похоже, работает на моем конце.

Отмечено, что вначале я использовал только набор: ssh_options, {:forward_agent => true} на 3 машинах, работающих на FreeBSD, CentOS и MacOSX, и он работал нормально - даже используется в производственных выпусках, однако после тестирования на VBoxed Vantage на базе бранного CentOS (6.4) машина перестала работать. Итак, добавление auth_method сделал трюк.

Смежные вопросы