简体   繁体   English

Ruby Net :: SSH Infinity等待密码

[英]Ruby Net::SSH infinity wait for password

I have a simple functional for run some command via ssh, here is an example: 我有一个简单的功能,可以通过ssh运行一些命令,这是一个示例:

...
Net::SSH.start( self.host, self.user, config: true, keys: [self.pem_key] ) do| ssh |
  result = ssh.exec! self.command
  ...

It works OK except case when I forgot configure remote host (as example add key in ~/.ssh/authorized) and my app stuck on password request: 除了我忘记配置远程主机(例如,在〜/ .ssh / authorized中添加密钥)并且我的应用卡在密码请求中的情况下,它可以正常工作:

Completed 200 OK in 246ms (Views: 238.1ms | ActiveRecord: 4.3ms)

Started POST "/xxx" for ::1 at 2016-05-24 13:43:11 +0300
Processing by XXX::XXXController#run_now as JS
Parameters: {"id"=>"2"}
XXX::Check Load (0.3ms)  SELECT  ...
(0.1ms)  BEGIN
SQL (0.3ms)  UPDATE ...
(0.3ms)  COMMIT
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
some_user@some_host's password:

How I can set timeout for this case or how I can exclude this case at all (raise some error?) 如何为这种情况设置超时或如何完全排除这种情况(引发一些错误?)

According to the documentation , the Net::SSH.start method accepts a :non_interactive => true option which should make your test (code) fail instead of asking for a password interactively. 根据文档Net::SSH.start方法接受一个:non_interactive => true Net::SSH.start :non_interactive => true选项,这会使您的测试(代码)失败,而不是交互地要求输入密码。 Other, non-interactive authentication options, such as the private key, will of course still work. 当然,其他非交互式身份验证选项(例如私钥)仍然可以使用。

So, try this: 因此,请尝试以下操作:

Net::SSH.start(self.host, self.user, config: true, non_interactive: true, keys: [self.pem_key]) do| ssh |
  ...
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM