ever get an error like this?


/sw/lib/ruby/gems/1.8/gems/net-ssh-1.1.1/lib/net/ssh/host-key-verifier.rb:47:in `process_cache_miss': fingerprint da:34:2e:a6:87:c4:c8:49:0e:a1:8e:39:fd:fc:ef:e7 does not match for threestonehearth.com (Net::SSH::HostKeyMismatch)
        from /sw/lib/ruby/gems/1.8/gems/net-ssh-1.1.1/lib/net/ssh/host-key-verifier.rb:38:in `verify'
        from /sw/lib/ruby/gems/1.8/gems/net-ssh-1.1.1/lib/net/ssh/lenient-host-key-verifier.rb:9:in `verify'
        from /sw/lib/ruby/gems/1.8/gems/net-ssh-1.1.1/lib/net/ssh/transport/kex/dh.rb:165:in `verify_server_key'
        from /sw/lib/ruby/gems/1.8/gems/net-ssh-1.1.1/lib/net/ssh/transport/kex/dh.rb:232:in `exchange_keys'
        from /sw/lib/ruby/gems/1.8/gems/needle-1.3.0/lib/needle/lifecycle/proxy.rb:60:in `__send__'
        from /sw/lib/ruby/gems/1.8/gems/needle-1.3.0/lib/needle/lifecycle/proxy.rb:60:in `method_missing'
        from /sw/lib/ruby/gems/1.8/gems/net-ssh-1.1.1/lib/net/ssh/transport/session.rb:182:in `exchange_keys'
        from /sw/lib/ruby/gems/1.8/gems/net-ssh-1.1.1/lib/net/ssh/transport/session.rb:143:in `kexinit'
         ... 49 levels...
        from /sw/lib/ruby/gems/1.8/gems/capistrano-1.99.1/lib/capistrano/cli/execute.rb:14:in `execute'
        from /sw/lib/ruby/gems/1.8/gems/capistrano-1.99.1/bin/cap:4
        from /sw/bin/cap:16:in `load'
        from /sw/bin/cap:16

Run this fix in irb.

require 'rubygems'
require 'net/ssh'
include Net

domain = '######' # insert IP address or domain name here

begin
  Net::SSH.start( domain ) do |ssh|
    # ...
  end
rescue Net::SSH::HostKeyMismatch => e
  puts "remembering new key: #{e.fingerprint}" 
  e.remember_host!
  retry
end

Based on a post by Jamis Buck

2 Responses to “fix Net::SSH error sometimes seen with capistrano”

  1. John Says:

    Excellent!

    You've saved my life, I was about to chuck the macbook thru the window.

    Thanks so much for posting this, really well done mate.

    John.

  2. Kamal Says:

    Hi, I used the suggested script as: modified script:

    require 'rubygems' require 'net/ssh' include Net

    Net::SSH.start( '10.5.30.52', 'root', :password => 'root' , :paranoid => false ) do|ssh| #puts "hello" end rescue Net::SSH::HostKeyMismatch => e puts "remembering new key: #{e.fingerprint}" e.remember_host! retry end

    but i am getting errors:

    rescue Net::SSH::HostKeyMismatch => e SyntaxError: compile error (irb):177: syntax error, unexpected kRESCUE rescue Net::SSH::HostKeyMismatch => e ^ (irb):177: syntax error, unexpected tASSOC rescue Net::SSH::HostKeyMismatch => e ^ from (irb):177 puts "remembering new key: #{e.fingerprint}" NameError: undefined local variable or method e' for main:Object from (irb):178 e.remember_host! NameError: undefined local variable or methode' for main:Object from (irb):179 retry LocalJumpError: retry outside of rescue clause from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/workspace.rb:81:in evaluate' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/context.rb:219:inevaluate' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:150:in eval_input' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:263:insignal_status' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:147:in eval_input' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:244:ineachtoplevel_statement' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in loop' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:230:ineachtoplevel_statement' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in catch' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:229:ineachtoplevel_statement' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:146:in eval_input' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:70:instart' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:69:in catch' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:69:instart' from /usr/bin/irb:13 Maybe IRB bug!! end SyntaxError: compile error (irb):181: syntax error, unexpected kEND from (irb):181

    need some help please.

    Thanks, -Kamal.

Leave a Reply