<?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>The Spark Between &#187; Linux</title>
	<atom:link href="http://www.mccambridge.org/blog/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mccambridge.org/blog</link>
	<description>Thoughts, Projects, Happenings, Ideas</description>
	<lastBuildDate>Sun, 20 Jun 2010 22:23:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Totally Seamless SSHFS under Linux using Fuse and Autofs</title>
		<link>http://www.mccambridge.org/blog/2007/05/totally-seamless-sshfs-under-linux-using-fuse-and-autofs/</link>
		<comments>http://www.mccambridge.org/blog/2007/05/totally-seamless-sshfs-under-linux-using-fuse-and-autofs/#comments</comments>
		<pubDate>Thu, 03 May 2007 04:28:34 +0000</pubDate>
		<dc:creator>Colin M</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Workedforme]]></category>

		<guid isPermaLink="false">http://www.mccambridge.org/blog/2007/05/totally-seamless-sshfs-under-linux-using-fuse-and-autofs/</guid>
		<description><![CDATA[You want to access a remote file system over SSH.  You want to use FUSE SSHFS, and you don't want to ever have to think about it, so you're looking for Autofs integration.]]></description>
			<content:encoded><![CDATA[<p><strong>This is awesome.</strong></p>
<p>I worked on this for something like 2 hours this afternoon, and finally tracked down all the nuances to get it working.  I&#8217;m really pleased with the results, and hope that they can be of some to use to you as well, because I could not find a decent tutorial on this subject despite extensive <a href="http://www.google.com">Googling</a>.</p>
<h3>The Problem: Connect to a remote filesystem over SSH</h3>
<p>Odds are if you&#8217;ve stumbled on this tutorial, you already know the problem: You want to access a remote file system over SSH.  You want to use FUSE SSHFS, and you don&#8217;t want to ever have to think about it, so you&#8217;re looking for Autofs integration.  To keep this to the point, I&#8217;m going to skip over the installation of these packages and just explain the configuration, especially since installation is very distribution specific.  I&#8217;ll simply say on my system (Ubuntu Feisty) it consisted of:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> sshfs autofs</pre></div></div>

<h3>The Solution</h3>
<p>Getting SSHFS to work with Autofs really isn&#8217;t hard, you just need the magic configuration.  Here&#8217;s how I got things working for me:</p>
<ol>
<li>Set up certificate authentication for your <em>local</em> <strong>root</strong> to the remote account on the remote machine, by use of <code class="inline">sudo ssh-keygen</code> locally, and the (remote account&#8217;s) <code class="inline">~/.ssh/authorized_keys</code> file.</li>
<li>Test the certificate authentication by verifying that the following command <em>does not</em> prompt for your remote password:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> remoteuser<span style="color: #000000; font-weight: bold;">@</span>remotehost <span style="color: #c20cb9; font-weight: bold;">uptime</span></pre></div></div>

</li>
<li>Test that sshfs can establish the requisite connection:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>sshfs_temp
<span style="color: #c20cb9; font-weight: bold;">sudo</span> sshfs remoteuser<span style="color: #000000; font-weight: bold;">@</span>remotehost: <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>sshfs_temp
<span style="color: #c20cb9; font-weight: bold;">sudo</span> fusermount <span style="color: #660033;">-u</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>sshfs_temp
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rmdir</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>sshfs_temp</pre></div></div>

<p>Note that the <code class="inline">:</code> is required after the host to specify the remote directory.  (<code class="inline">:</code> alone means the remote user&#8217;s home.  <code class="inline">:/remote/path</code> indicates a remote path.)</li>
<li>Add the following line to your <strong><code class="inline">/etc/auto.master</code></strong> file:
<pre lang="bash" class="numbered"><strong>/mnt/ssh</strong> /etc/auto.sshfs        uid=<strong>1000</strong>,gid=<strong>1000</strong>,--timeout=<strong>30</strong>,--ghost</pre>
<p>Where <strong>/mnt/ssh</strong> is the path you want all ssh automounts to appear in,<br />
<strong>1000</strong> is the UID of the user you want the sshfs mount to belong to (i.e., be writable by),<br />
<strong>1000</strong> is the GID of the user you want the sshfs mount to belong to, and<br />
<strong>30</strong> is the timeout in seconds to keep the FUSE connection alive.</li>
<li>Copy the following into a new file <strong><code class="inline">/etc/auto.sshfs</code></strong>:
<pre lang="text" class="numbered">#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
remote1     -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#remoteuser@remotehost1\:
remote2  -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#remoteuser2@remotehost2\:/remote/path
</pre>
<p>This creates two sshfs mappings (obviously, adding or removing lines creates more or fewer mappings).<br />
The first will be at <code class="inline">/mnt/ssh/remote1</code>, and map to the home directory of <code class="inline">remoteuser</code> on the host <code class="inline">remotehost1</code>.<br />
The second will be at <code class="inline">/mnt/ssh/remote2</code>, and map to the directory <code class="inline">/remote/path</code> on the host <code class="inline">remotehost2</code>, with the permissions of the user <code class="inline">remoteuser2</code>.<br />
<strong>Note the <code class="inline">\</code> characters to escape <code class="inline">#</code> and <code class="inline">:</code></strong>  These escape characters are what took me two hours to track down:  FUSE requires a parameter of the form: <code class="inline">sshfs#user@host:directory</code>, but autofs treats everything following a <code class="inline">#</code> as a comment, and the <code class="inline">:</code> character has a special meaning.  These characters must be escaped by a <code class="inline">\</code></li>
<li>Restart autofs to reload the configuration files:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>autofs restart</pre></div></div>

</li>
<li>Test it out!  As root or the user indicated by <code class="inline">uid</code> above, run:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>remote1</pre></div></div>

<p>You should be greeted by the contents of the remote file system.  Congratulations!</li>
</ol>
<h3>The Problems</h3>
<ul>
<li>This exact setup only works for one user due to specifying a uid.  This is fine for a home desktop system, but will likely need further work to allow multiple users access to the remote filesystem.  Perhaps careful usage of gid could alleviate this problem, though logging into the remote machine as a specific user still represents a security risk.</li>
<li>I have not examined the architecture enough since I am only seeking to enable my home desktop system, so <strong>I cannot vouch for the security of this setup</strong> whatsoever.  For example, the use of the allow_other option for FUSE may have security consequences since the mountpoint is created as root (to my understanding, at least).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.mccambridge.org/blog/2007/05/totally-seamless-sshfs-under-linux-using-fuse-and-autofs/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
