Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ruby'检查代理是否提供私钥;s Net::SSH_Ruby_Ssh - Fatal编程技术网

使用Ruby'检查代理是否提供私钥;s Net::SSH

使用Ruby'检查代理是否提供私钥;s Net::SSH,ruby,ssh,Ruby,Ssh,我正在使用Net::SSH自动访问ruby程序,使用密钥身份验证从中删除主机。该程序不指定用户应将私钥放在何处,而是依赖用户的SSH代理提供所需的密钥(它应该这样做) 问题是,如果所需的私钥不可用,连接将失败——这可能会在程序运行很长一段时间后发生(SSH连接是我们在执行了许多其他操作(不容易恢复)后最后要做的事情之一) 假设我知道用户应该拥有什么私钥(由密钥指纹指定),我如何从ruby-other执行此检查,然后执行ssh add-l并对输出进行grepping 我已经看过Net::SSH K

我正在使用Net::SSH自动访问ruby程序,使用密钥身份验证从中删除主机。该程序不指定用户应将私钥放在何处,而是依赖用户的SSH代理提供所需的密钥(它应该这样做)

问题是,如果所需的私钥不可用,连接将失败——这可能会在程序运行很长一段时间后发生(SSH连接是我们在执行了许多其他操作(不容易恢复)后最后要做的事情之一)

假设我知道用户应该拥有什么私钥(由密钥指纹指定),我如何从ruby-other执行此检查,然后执行
ssh add-l
并对输出进行grepping


我已经看过Net::SSH KeyFactory类,但它只允许您在知道私钥存储文件名的情况下加载私钥

我想出来了-
Net::SSH::Authentication::KeyManager
有我需要的:

hasidentity = false
Net::SSH::Authentication::KeyManager.new(nil?).each_identity do |i| 
  hasidentity |= i.fingerprint == 'my:ke:ys:fi:ng:er:pr:in:t'
end
KeyManager
还有一个名为
identifies
的集合,但据我所知,该集合只保存直接加载到Net::SSH中的密钥,而
每个_identity
都会迭代所有可用的标识,包括代理中可用的标识