<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#187; net-ssh</title>
	<atom:link href="http://blog.cliffano.com/tag/net-ssh/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cliffano.com</link>
	<description>Geeking, Living, Travelling</description>
	<lastBuildDate>Thu, 26 Jan 2012 10:18:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Known Hosts Issue With Net::SSH</title>
		<link>http://blog.cliffano.com/2010/01/19/known-hosts-issue-with-netssh/</link>
		<comments>http://blog.cliffano.com/2010/01/19/known-hosts-issue-with-netssh/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 13:25:48 +0000</pubDate>
		<dc:creator>Cliffano Subagio</dc:creator>
				<category><![CDATA[Work]]></category>
		<category><![CDATA[.ssh]]></category>
		<category><![CDATA[known_hosts]]></category>
		<category><![CDATA[net-ssh]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.cliffano.com/?p=889</guid>
		<description><![CDATA[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&#8217;s supposed to perform some remote operations. [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>So I was using <a href="http://net-ssh.rubyforge.org">net-ssh</a>-2.0.15 and <a href="http://github.com/jruby/jruby-openssl">jruby-openssl</a>-0.5.1 for a piece of code that&#8217;s supposed to perform some remote operations. The Net::SSH usage itself was straightforward&#8230;</p>
<pre class="brush: ruby; title: ; notranslate">
Net::SSH.start(@host, @username, :keys =&gt; @keys) do |ssh|
    ...
end
</pre>
<p>When I ran the above snippet on Windows XP, it gave this error message without any further information&#8230;</p>
<pre class="brush: plain; title: ; notranslate">
The system cannot find the path specified
</pre>
<p>Not exactly helpful, eh? And after some sleuthing around, it came down to <code>add(host, key)</code> method in lib/net/ssh/known_hosts.rb :</p>
<pre class="brush: ruby; title: ; notranslate">
def add(host, key)
  File.open(source, &quot;a&quot;) do |file|
    blob = [Net::SSH::Buffer.from(:key, key).to_s].pack(&quot;m*&quot;).gsub(/\s/, &quot;&quot;)
    file.puts &quot;#{host} #{key.ssh_type} #{blob}&quot;
  end
end
</pre>
<p>This method is trying to add an entry to the known_hosts file, which location is stored in <code>source</code> variable. In my case, the variable resolved to C:/.ssh/known_hosts . But the problem was that the .ssh directory didn&#8217;t exist. So I simply created it.</p>
<p>Lo and behold, when I ran this piece of code on a Solaris box weeks later, I hit another error message&#8230;</p>
<pre class="brush: plain; title: ; notranslate">
No such file or directory (IOError)
</pre>
<p>which turned out to be caused by the exact same thing, but this time the location is &lt;script_home&gt;/.ssh/known_hosts . The workaround was the same, I simply created the .ssh directory.</p>
<p>So there you go, hopefully it helps whoever else was confused by the unclear error messages.<br />
And in terms of a long term solution, it would be nice if <code>add(host, key)</code> checks or even creates the .ssh directory before attempting to write known_hosts file.</p>

<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fblog.cliffano.com%2F2010%2F01%2F19%2Fknown-hosts-issue-with-netssh%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cliffano.com/2010/01/19/known-hosts-issue-with-netssh/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

