2011-07-26 15 views
11

के साथ चाबियों का उपयोग करके कनेक्ट नहीं किया जा सकता है मुझे नेट नेट एसएसएच :: प्रमाणीकरणफेल प्राप्त करने के लिए 'नेट-एसएसएच' मणि का उपयोग करके रूबी से एसएसएच के माध्यम से कनेक्ट करने में समस्या हो रही है। कोडरुबी और नेट/एसएसएच

require 'net/ssh' 
keys = ["path_to_private_key"] 
Net::SSH.start('host', 'user',:keys => keys, :verbose => :debug) do |ssh| 
    #ssh code 

end 

नीचे है कमांड लाइन से सीधे ssh का उपयोग करते हुए काम करता है:

ssh -i <path_to_private_key> [email protected] 

मैं ssh एपीआई गलत है? मैंने एक ही परिणाम के साथ उपयोगकर्ता नाम के रूप में 'उपयोगकर्ता @ होस्ट' और बस 'उपयोगकर्ता' दोनों को आजमाया है।

D, [2011-07-26T19:42:00.135148 #3511] DEBUG -- net.ssh.transport.session[140b040]: establishing connection to host:22 
D, [2011-07-26T19:42:00.164190 #3511] DEBUG -- net.ssh.transport.session[140b040]: connection established 
I, [2011-07-26T19:42:00.164344 #3511] INFO -- net.ssh.transport.server_version[140a3fc]: negotiating protocol version 
D, [2011-07-26T19:42:00.192092 #3511] DEBUG -- net.ssh.transport.server_version[140a3fc]: remote is `SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu3' 
D, [2011-07-26T19:42:00.192177 #3511] DEBUG -- net.ssh.transport.server_version[140a3fc]: local is `SSH-2.0-Ruby/Net::SSH_2.1.4 x86_64-linux' 
D, [2011-07-26T19:42:00.212348 #3511] DEBUG -- tcpsocket[140aaf0]: read 784 bytes 
D, [2011-07-26T19:42:00.212461 #3511] DEBUG -- tcpsocket[140aaf0]: received packet nr 0 type 20 len 780 
I, [2011-07-26T19:42:00.212515 #3511] INFO -- net.ssh.transport.algorithms[13e9058]: got KEXINIT from server 
I, [2011-07-26T19:42:00.212604 #3511] INFO -- net.ssh.transport.algorithms[13e9058]: sending KEXINIT 
D, [2011-07-26T19:42:00.212698 #3511] DEBUG -- tcpsocket[140aaf0]: queueing packet nr 0 type 20 len 556 
D, [2011-07-26T19:42:00.212741 #3511] DEBUG -- tcpsocket[140aaf0]: sent 560 bytes 
I, [2011-07-26T19:42:00.212771 #3511] INFO -- net.ssh.transport.algorithms[13e9058]: negotiating algorithms 
D, [2011-07-26T19:42:00.212859 #3511] DEBUG -- net.ssh.transport.algorithms[13e9058]: 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, [2011-07-26T19:42:00.212889 #3511] DEBUG -- net.ssh.transport.algorithms[13e9058]: exchanging keys 
D, [2011-07-26T19:42:00.212998 #3511] DEBUG -- tcpsocket[140aaf0]: queueing packet nr 1 type 34 len 20 
D, [2011-07-26T19:42:00.213033 #3511] DEBUG -- tcpsocket[140aaf0]: sent 24 bytes 
D, [2011-07-26T19:42:00.292238 #3511] DEBUG -- tcpsocket[140aaf0]: read 152 bytes 
D, [2011-07-26T19:42:00.292389 #3511] DEBUG -- tcpsocket[140aaf0]: received packet nr 1 type 31 len 148 
D, [2011-07-26T19:42:00.297526 #3511] DEBUG -- tcpsocket[140aaf0]: queueing packet nr 2 type 32 len 140 
D, [2011-07-26T19:42:00.297627 #3511] DEBUG -- tcpsocket[140aaf0]: sent 144 bytes 
D, [2011-07-26T19:42:00.321754 #3511] DEBUG -- tcpsocket[140aaf0]: read 720 bytes 
D, [2011-07-26T19:42:00.321909 #3511] DEBUG -- tcpsocket[140aaf0]: received packet nr 2 type 33 len 700 
D, [2011-07-26T19:42:00.326688 #3511] DEBUG -- tcpsocket[140aaf0]: queueing packet nr 3 type 21 len 20 
D, [2011-07-26T19:42:00.326793 #3511] DEBUG -- tcpsocket[140aaf0]: sent 24 bytes 
D, [2011-07-26T19:42:00.326927 #3511] DEBUG -- tcpsocket[140aaf0]: received packet nr 3 type 21 len 12 
D, [2011-07-26T19:42:00.327325 #3511] DEBUG -- net.ssh.authentication.session[1475c10]: beginning authentication of `[email protected]' 
D, [2011-07-26T19:42:00.327519 #3511] DEBUG -- tcpsocket[140aaf0]: queueing packet nr 4 type 5 len 28 
D, [2011-07-26T19:42:00.327604 #3511] DEBUG -- tcpsocket[140aaf0]: sent 52 bytes 
D, [2011-07-26T19:42:00.461124 #3511] DEBUG -- tcpsocket[140aaf0]: read 52 bytes 
D, [2011-07-26T19:42:00.461199 #3511] DEBUG -- tcpsocket[140aaf0]: received packet nr 4 type 6 len 28 
D, [2011-07-26T19:42:00.461260 #3511] DEBUG -- net.ssh.authentication.session[1475c10]: trying publickey 
D, [2011-07-26T19:42:00.461370 #3511] DEBUG -- net.ssh.authentication.agent[1470800]: connecting to ssh-agent 
E, [2011-07-26T19:42:00.461423 #3511] ERROR -- net.ssh.authentication.agent[1470800]: could not connect to ssh-agent 
D, [2011-07-26T19:42:00.461521 #3511] DEBUG -- net.ssh.authentication.methods.publickey[1470bfc]: trying publickey (d7:62:48:07:23:1d:c0:de:80:0d:27:a3:ab:92:72:be) 
D, [2011-07-26T19:42:00.461610 #3511] DEBUG -- tcpsocket[140aaf0]: queueing packet nr 5 type 50 len 364 
D, [2011-07-26T19:42:00.461648 #3511] DEBUG -- tcpsocket[140aaf0]: sent 388 bytes 
D, [2011-07-26T19:42:00.486881 #3511] DEBUG -- tcpsocket[140aaf0]: read 68 bytes 
D, [2011-07-26T19:42:00.487057 #3511] DEBUG -- tcpsocket[140aaf0]: received packet nr 5 type 51 len 44 
D, [2011-07-26T19:42:00.487186 #3511] DEBUG -- net.ssh.authentication.session[1475c10]: allowed methods: publickey,password 
D, [2011-07-26T19:42:00.487261 #3511] DEBUG -- net.ssh.authentication.session[1475c10]: trying password 
E, [2011-07-26T19:42:00.487346 #3511] ERROR -- net.ssh.authentication.session[1475c10]: all authorization methods failed (tried publickey, password) 

धन्यवाद

+0

आपका कोड काम करना चाहिए, क्या आपको यकीन है कि आपके पथ कोड में "path_to_private_key" सही है? डिबगिंग आउटपुट क्या दिखाता है? –

+0

@ जेफ-डेलियन मैंने प्रश्न में आउटपुट जोड़ा। – grant

उत्तर

8
$ ssh-keygen -t rsa  
$ ssh-copy-id -i ~/.ssh/id_dsa.pub [email protected] 
$ ssh [email protected] 

require 'net/ssh' 
require 'logger' 

Net::SSH.start(
    'host', 'user', 
    :host_key => "ssh-rsa", 
    :encryption => "blowfish-cbc", 
    :keys => [ "~/.ssh/id_rsa.pub" ], 
    :compression => "zlib" 
) do |session| 
    ... 
end 

कि तुम मदद करनी चाहिए:

यहाँ डिबगिंग आउटपुट है!

+0

धन्यवाद, लेकिन जब तक इस प्रश्न का उत्तर दिया गया था, तब तक मैंने इस मुद्दे को पीछे छोड़ दिया था, और भूल गया था कि मैंने यह भी पूछा :) – grant

+4

यह क्यों काम करता है लेकिन मूल पोस्ट नहीं? होस्ट_की, एन्क्रिप्शन, या संपीड़न निर्दिष्ट करता है, और यदि ऐसा है तो क्यों? –

+4

जिस तरह से ऊपर दिए गए उदाहरण में कुंजी विकल्प का तात्पर्य है कि यह एक सार्वजनिक कुंजी की तलाश में है, यह एक निजी कुंजी होना चाहिए। –