使用Ruby和净-SSH,我怎么可以验证使用与网:: SSH.start的key_data参数? [英] Using Ruby and net-ssh, how do I authenticate using the key_data parameter with Net::SSH.start?

查看:147
本文介绍了使用Ruby和净-SSH,我怎么可以验证使用与网:: SSH.start的key_data参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过的净-SSH的文档,我仍然感到困惑。键参数:我可以通过将关键在一个文件中,并使用人工进行验证(使用ssh -i ...),而还。不过,我不想使用:按键的参数,我想用:key_data参数。谁能给一个工作的例子吗?出于某种原因,直接喂养串入:key_data不能正常工作,并给出了错误:无论PUB键也不PRIV键::嵌套ASN1错误。当然,我用Google搜索这一点,这主要是告诉我,以确保关键是PEM格式。而且,当然是。有任何想法吗?我可以提供更详细的信息,如果需要的...

I've read the net-ssh documentation, and I am still perplexed. I can authenticate manually (using ssh -i ...), and also by placing the key in a file and using the :keys parameter. However, I dont want to use the :keys parameter, I want to use the :key_data parameter. Can anyone give a working example? For some reason, directly feeding a string into :key_data is not working, and it gives the error: "Neither PUB key nor PRIV key:: nested asn1 error". Of course I googled that, and it basically tells me to make sure the key is in PEM format. And, of course it is. Any ideas? I can provide more detailed info if needed...

推荐答案

我看到了pretty这个问题,旧的,但我要的答案扔你反正以防万一,因为我有同样的问题,我只是解决它。

I see this question in pretty old but I am going to throw the answer to you anyway just in case as I had the same issue and I just solved it.

在以下code要注意的是RSA密钥字符串是没有缩进在所有的任何地方。密钥的第二行不具有任何前导空格。 TextMate的把这个那里,当我粘贴的钥匙。我删除它和它的工作就像一个魅力。

In the following code note that the string containing the RSA key is not indented at all anywhere. The second line of the key does not have any leading space in it. TextMate put this there when I pasted the key in. I removed it and it worked like a charm.

#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'

HOST = '172.20.0.31'
USER = 'root'

KEYS = [ "-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAqccvUza8FCinI4X8HSiXwIqQN6TGvcNBJnjPqGJxlstq1IfU
kFa3S9eJl+CBkyjfvJ5ggdLN0S2EuGWwc/bdE3LKOWX8F15tFP0=
-----END RSA PRIVATE KEY-----" ]

Net::SSH.start( HOST, USER, :key_data => KEYS, :keys_only => TRUE) do|ssh|
result = ssh.exec!('ls')
puts result
end

这篇关于使用Ruby和净-SSH,我怎么可以验证使用与网:: SSH.start的key_data参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆