简体   繁体   English

ruby on rails net ssh strickhostkeychecking =否

[英]ruby on rails net ssh strickhostkeychecking=no

Hi i have a net:ssh connection in the controller . 嗨,我在controller有一个net:ssh连接。 I might change the host name dynamically while establishing the connection. 建立连接时,我可能会动态更改host name But when it logs in for the first time, shell might ask permission whether to connect or not. 但是,当它第一次登录时,shell可能会询问是否连接。 Since iam connecting to it through the web, i could not see any pop up asking me. 由于iam通过网络连接到它,因此我看不到任何弹出窗口问我。 Hence i read https://groups.google.com/group/comp.lang.tcl/browse_thread/thread/ca0cd6ec905eb702 and i want to add "-oStrictHostKeyChecking=no" this tag while connecting to the host. 因此,我阅读了https://groups.google.com/group/comp.lang.tcl/browse_thread/thread/ca0cd6ec905eb702,并且我想在连接到主机时添加"-oStrictHostKeyChecking=no"此标记。 As we know the below is the standard format of net::ssh in rails 众所周知,以下是net :: ssh在rails中的标准格式

     @HOST = 'hostname'
     @USER = 'username'
     @PASS = 'password'

     Net::SSH.start( @HOST, @USER, :password => @PASS ) do|ssh|

Where would i pass this extra parameter "-oStrictHostKeyChecking=no" while establishing the connection? 建立连接时,我应该在哪里传递此额外参数"-oStrictHostKeyChecking=no"

I already tried 我已经试过了

@HOST = 'hostname -oStrictHostKeyChecking=no'

But it does not work. 但这行不通。 Please help 请帮忙

You can possibly use ruby's begin/rescue like following, which will handle the host key mismatch by remembering the host and retrying the connection. 您可以像下面这样使用ruby的begin / rescue,它将通过记住主机并重试连接来处理主机密钥不匹配的情况。

begin
  Net::SSH.start(@host, @user, :password => @pass) do |ssh|
    ... #what ever you want to do
  end
rescue Net::SSH::HostKeyMismatch => e
  e.remember_host!
  retry
end

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

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