我正在尝试使用 ruby gem net-ssh
并收到如下所述的错误
jruby-9.1.15.0 :001 > require "net/ssh"
=> true
jruby-9.1.15.0 :002 > Net::SSH.start('myhost.dev', 'username' password: 'password', verbose: Logger::DEBUG){|ssh| puts ssh.exec!('hostname')}
D, [2018-01-17T14:24:29.633089 #26123] DEBUG -- net.ssh.transport.session[7d0]: establishing connection to myhost.dev:22
D, [2018-01-17T14:24:29.884816 #26123] DEBUG -- net.ssh.transport.session[7d0]: connection established
I, [2018-01-17T14:24:29.888234 #26123] INFO -- net.ssh.transport.server_version[7d2]: negotiating protocol version
D, [2018-01-17T14:24:29.888926 #26123] DEBUG -- net.ssh.transport.server_version[7d2]: local is `SSH-2.0-Ruby/Net::SSH_4.2.0 java'
D, [2018-01-17T14:24:29.952538 #26123] DEBUG -- net.ssh.transport.server_version[7d2]: remote is `SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8'
NotImplementedError: unsupported key type `ecdsa-sha2-nistp256'
from /home/qpi/.rvm/gems/jruby-9.1.15.0@some_gem/gems/net-ssh-4.2.0/lib/net/ssh/buffer.rb:286:in `read_keyblob'
从 buffer.rb:286:in read_keyblob
引发错误。
Here引发错误的代码部分
unless defined?(OpenSSL::PKey::EC)
raise NotImplementedError, "unsupported key type `#{type}'"
好的..让我们检查是否定义了OpenSSL::PKey::EC
:
jruby-9.1.15.0 :003 > defined?(OpenSSL::PKey::EC) ? 'defined' : 'not defined'
=> "defined"
我做错了什么?
当我使用ruby
(不是jruby
)时,一切正常
最佳答案
这不是一个真正的解决方案,但我找到了一个对我有用的技巧。
https://github.com/jruby/jruby-openssl/issues/105
简而言之,在 Net::SFTP.start 之前,放置这两行。
Net::SSH::Transport::Algorithms::ALGORITHMS.values.each { |algs| algs.拒绝! { |a| a =~/^ecd(sa|h)-sha2/} }
Net::SSH::KnownHosts::SUPPORTED_TYPE.拒绝! {|t| t =~/^ecd(sa|h)-sha2/}
你的问题应该就消失了。
关于jruby - 为什么不支持 key 类型 ecdsa-sha2-nistp256?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48301264/