使用 Ruby 和 net-ssh,如何使用 Net::SSH.start 的 key_data 参数进行身份验证?
我已经阅读了 net-ssh 文档,但仍然感到困惑。我可以手动进行身份验证(使用 ssh -i ...),也可以将密钥放入文件中并使用 :keys 参数。但是,我不想使用 :keys 参数,我想使用 :key_data 参数。谁能举一个可行的例子吗?由于某种原因,直接将字符串输入 :key_data 不起作用,并且它会给出错误:“既没有 PUB key 也没有 PRIV key:: 嵌套 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看到这个问题已经很老了,但无论如何我都会把答案告诉你,以防万一我遇到了同样的问题并且我刚刚解决了它。
请注意,在以下代码中,包含 RSA 密钥的字符串在任何地方都没有缩进。密钥的第二行中没有任何前导空格。当我粘贴密钥时,TextMate 将其放在那里。我将其删除,它就像一个魅力。
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.
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.
我添加了一些我在挖掘库后发现的更多信息...
从 2.9.2 开始,如果您的意图是仅使用 key_data 中提供的密钥,则还必须在加载之前指定一组空白密钥key_data,否则会加载一些默认的键。
就我而言,它尝试加载的身份文件之一受密码保护,因此它要求我提供密码,尽管我的意图根本不是使用该身份文件。
使用上面的示例,在 2.9.2 中,您可以通过执行以下操作获得相同的效果:
I'm adding a little more info that I discovered myself after digging around the library...
Since 2.9.2, if your intention is to use only the key provided in key_data, you must also specify a blank set of keys before loading your key_data, or it will load some default keys.
In my case, one of those identity files it tried to load was passphrase-protected, so it asked me for my passphrase, though my intention was not to use that identify file at all.
Using the example above, in 2.9.2, you can get the same effect by doing something like this: