19 Jan 2010, 12:25am
Work:
by Cliffano Subagio

3 comments
  • Known Hosts Issue With Net::SSH

    This issue bit me twice within a month, and each time I had to spend a couple of hours to figure out the cause of the problem, mostly due to the obscurity of the error messages.

    So I was using net-ssh-2.0.15 and jruby-openssl-0.5.1 for a piece of code that’s supposed to perform some remote operations. The Net::SSH usage itself was straightforward…

    Net::SSH.start(@host, @username, :keys => @keys) do |ssh|
        ...
    end
    

    When I ran the above snippet on Windows XP, it gave this error message without any further information…

    The system cannot find the path specified
    

    Not exactly helpful, eh? And after some sleuthing around, it came down to add(host, key) method in lib/net/ssh/known_hosts.rb :

    def add(host, key)
      File.open(source, "a") do |file|
        blob = [Net::SSH::Buffer.from(:key, key).to_s].pack("m*").gsub(/\s/, "")
        file.puts "#{host} #{key.ssh_type} #{blob}"
      end
    end
    

    This method is trying to add an entry to the known_hosts file, which location is stored in source variable. In my case, the variable resolved to C:/.ssh/known_hosts . But the problem was that the .ssh directory didn’t exist. So I simply created it.

    Lo and behold, when I ran this piece of code on a Solaris box weeks later, I hit another error message…

    No such file or directory (IOError)
    

    which turned out to be caused by the exact same thing, but this time the location is <script_home>/.ssh/known_hosts . The workaround was the same, I simply created the .ssh directory.

    So there you go, hopefully it helps whoever else was confused by the unclear error messages.
    And in terms of a long term solution, it would be nice if add(host, key) checks or even creates the .ssh directory before attempting to write known_hosts file.

    Related Posts:

    hey, may I know what is the plugin used here for displaying code?

    Many thanks.

    24 Feb 2010, 5:45pm
    by Cliffano Subagio

    reply
    23 Apr 2010, 2:27am
    by Cliffano Subagio

    reply

    I’ve started replacing it with SyntaxHighlighter Evolved http://wordpress.org/extend/plugins/syntaxhighlighter/

    The old google-syntax-highlighter plugin includes too many JavaScript files.

     
    leave a comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *name

    *e-mail

    web site


    *name

    *e-mail

    web site

    leave a comment


     

    Recent Posts

    Recent Comments

    • Chess Strategizer: This just got bookmarked! “That’s why I always think of Simon Bolivar and remember that...
    • David from getcheaptrainfares.co.uk: Thank you very much for sharing your wonderful tips! That would definitely be a...
    • Natasha: The quote “Find the best in everybody. Just keep waiting no matter how long it takes. No one is all...
    • Alfonzo Donkin: Stumbled upon your website via bing the other day and absolutely think its great. Carry on the great...
    • Cliffano Subagio: Sure thing.

    Most Commented Posts

    Linkroll