Need to ignore HostKeyMismatch when logging in using Net::SSH.start()
-
01-10-2019 - |
Question
:paranoid => false
in the Net::SSH.start() does not seem to work
Solution
You can pass a Null verifier instead of false: :paranoid => Net::SSH::Verifiers::Null.new
.
This is essentially what you should get when passing false but it doesn't appear to always work for some reason.
Please note, just to be explicit. This does not ignore the HostKeyMismatch exception, rather it does not even attempt to verify the host key (the exception does not get raised at all).
OTHER TIPS
Just to want to add one more thing to this.
You can also use remember_host
method of Net::SSH::HostKeyError
to record this host and key in the known hosts file.
Example :
begin
.
.
rescue Net::SSH::HostKeyError => e
e.remember_host!
retry
end
Source : http://www.rubydoc.info/github/net-ssh/net-ssh/Net/SSH/HostKeyError#remember_host!-instance_method