2012-03-06 2 views
3

Ruby를 사용하는 SSH를 사용하여 서버에 연결하려고 시도했지만 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

이 문제를 해결하는 방법을 찾았습니다 : Net::SSH.start 함수에 :auth_methods => ['publickey','password'] 매개 변수를 추가하십시오.

+0

체크 아웃 : 보석 제거 그물 SSH에게 -v 2.8.0를, 나를 위해 작동 는 참조 ': non_interactive => true' – nhed

0

나는 Net :: SSH.start 솔루션을 사용하지 않았지만 내 마지막에는 작동하는 것처럼 보이는 set :ssh_options, {:forward_agent => true, :auth_methods => 'publickey'}을 선택했다.

처음에는 FreeBSD, CentOS 및 MacOSX에서 실행되는 3 개의 컴퓨터에서 set : ssh_options, {:forward_agent => true}을 사용했는데 정상적으로 작동했습니다. 그러나 VBoxed Vagrant 기반 CentOS (6.4)에서 테스트 한 후에는 프로덕션 릴리스에서도 사용되었습니다. 기계가 작동을 멈췄습니다. 그래서, auth_method를 추가하는 것이 트릭을 만들었습니다.

내가 전에 그 오류를 본