如何检查SSH连接5.2和NET :: SSH。
我需要检查与我使用的远程服务器的SSH连接是否正确。
我发出以下测试:
begin
session = Net::SSH.start(uri, login, password: password)
session.close
Rails.logger.interactions.info ' Successful SSH connection'
rescue
Rails.logger.interactions.info ' Unable to connect via SSH'
end
当URI不正确(服务器未开头)时,将按预期调用救援分支。
但是,如果凭据不正确,服务器控制台将切换到交互式模式,并要求密码:
[email protected]'s password:
并且在输入某些内容之前不会发布。
如何避免这种情况并跳到例外?
多谢!
I need to check whether the SSH connection to a remote server I use is correct or not.
I issue the following test:
begin
session = Net::SSH.start(uri, login, password: password)
session.close
Rails.logger.interactions.info ' Successful SSH connection'
rescue
Rails.logger.interactions.info ' Unable to connect via SSH'
end
When the uri is incorrect (the server is unknonw), the rescue branch is invoked as expected.
But if the credentials are incorrect, the server console switches to interactive mode, and claims for a password:
[email protected]'s password:
And does not release until something is entered.
How to avoid this and jump to the exception instead?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
non_interactive start 方法的选项避免切换到新凭据的交互式请求。
以下声明解决了我的问题:
The non_interactive option of the start method avoids switching to interactive request for new credentials.
The following statement solved my issue: