<?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>stu.mp &#187; debian</title>
	<atom:link href="http://stu.mp/category/debian/feed" rel="self" type="application/rss+xml" />
	<link>http://stu.mp</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 25 Oct 2012 18:52:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Secure iDisk with WebDAV+SSL+PAM on Debian/Apache2</title>
		<link>http://stu.mp/2006/06/webdavsslpam-on-debianapache2.html</link>
		<comments>http://stu.mp/2006/06/webdavsslpam-on-debianapache2.html#comments</comments>
		<pubDate>Tue, 20 Jun 2006 00:13:03 +0000</pubDate>
		<dc:creator>joestump</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[webdave]]></category>

		<guid isPermaLink="false">http://www.joestump.net/2006/06/webdavsslpam-on-debianapache2.html</guid>
		<description><![CDATA[I&#8217;ve been putting together a new file server for personal use that I plan on hosting on my DSL at home (7mbit/896kbit). I have Gig-E inside my condo and just shy of 1mbit from outside my condo over a static &#8230; <a href="http://stu.mp/2006/06/webdavsslpam-on-debianapache2.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>
I&#8217;ve been putting together a new file server for personal use that I plan on hosting on my DSL at home (7mbit/896kbit). I have Gig-E inside my condo and just shy of 1mbit from outside my condo over a static IP address. More than enough bandwidth to serve my personal email, my website along with a few friends&#8217; sites and email. The next question, of course, is what to do with the hundreds of gigabytes laying vacant on the server.
</p>
<p>
Being that I run OS X 10.4 and so do my other friends the obvious solution was <a href="http://www.webdav.org">WebDAV</a> over SSL. I wanted to be able to mount my <code>$HOME/public_html</code> over SSL using PAM for authentication. Surprisingly, this actually works with a few hacks.
</p>
<div class="alert">
<h4>Warning</h4>
<p>
The rest of this article includes a few hacks that mess with permissions in a way that some people will scoff at. I understand this fully and am using this little space to warn you ahead of time that doing this <em>will give Apache access to your <code>/etc/shadow</code> file</em>.
</p>
</div>
<h3>List of Ingredients</h3>
<ol>
<li>An installation of Debian GNU/Linux running Apache2 (specifically <code>apache2</code>, <code>apache2-common</code>, <code>apache2-utils</code>, and <code>libapache2-mod-auth-pam</code>)</li>
<li>Everyone&#8217;s favorite scheduler, <code>cron</code></li>
<li>A text editor</li>
</ol>
<h3>Enabling/Disabling the appropriate Apache2 modules</h3>
<p>
Using the script <code>a2enmod</code> you&#8217;ll want to enable <code>auth_pam</code>, <code>dav_fs</code>, <code>dav</code> and <code>ssl</code>. These are the basic modules required to get this setup going. You might also be interested in installing the <code>php5</code> module, etc. I won&#8217;t be covering that in this section. You will actually want to <em>disable</em> the <code>userdir</code> module. I did this mainly to disable WebDAV from working under the non-SSL Apache2 instances. I now include these files directly from my SSL <code>&lt;VirtualHost&gt;</code> configuration.
</p>
<h3>Setting up the SSL <code>&lt;VirtualHost&gt;</code> in <code>/etc/apache2/sites-available/default</code></h3>
<pre><code>
NameVirtualHost *:443
&lt;VirtualHost *:443&gt;
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/apache.pem
    DocumentRoot /var/www/
    Include /etc/apache2/mods-available/userdir.load
    Include /etc/apache2/mods-available/userdir.conf
&lt;/VirtualHost&gt;
</code></pre>
<h3>Setting up the WebDAV in <code>/etc/apache2/mods-available/userdir.conf</code></h3>
<pre><code>
&lt;IfModule mod_userdir.c&gt;
    UserDir public_html
    UserDir disabled root

    # Make sure to chown www-data:www-data this file
    DAVLockDB /var/lib/apache2/DAVLockDB
    &lt;Directory /home/*/public_html&gt;
        AllowOverride FileInfo AuthConfig Limit
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
        DAV On

        AuthPAM_Enabled On
        AuthPAM_FallThrough Off

        # This is so when you edit files over DAV they
        # aren't ran through pre-processors (ie. PHP)
        ForceType text/plain
    &lt;/Directory&gt;
&lt;/IfModule&gt;
</code></pre>
<h3>Allow <code>www-data</code> to view <code>/etc/shadow</code></h3>
<p>
By default only <code>root</code> and those in the group <code>shadow</code> can view <code>/etc/shadow</code>. Add the user <code>www-data</code> to the group <code>shadow</code>. Now is probably a good time to restart apache using <code>/etc/init.d/apache2 force-reload</code> if you haven&#8217;t already.
</p>
<h3>Setting up the <code>$HOME/public_html</code></h3>
<p>
In your <code>$HOME</code> you&#8217;re going to want to create <code>public_html</code> and <code>chown $USER:www-data public_html</code> along with <code>chmod 775 public_html</code>. This allows both <code>$USER</code> and <code>www-data</code> to modify the contents of <code>public_html</code>.
</p>
<h3>Editing <code>$HOME/public_html/.htaccess</code></h3>
<p>
After this <code>cd</code> into <code>public_html</code> and open up <code>.htaccess</code> and add the following lines to it (replace $USER with whomever&#8217;s $HOME you&#8217;re putting this in).
</p>
<pre><code>
AuthPAM_Enabled on
AuthType Basic
AuthName "PAM"

# If the user you're creating this for is /home/jstump then
# replace $USER with jstump
require user $USER
</code></pre>
<p>
This is pretty key as it allows you to keep authentication for your WebDAV and SSH tied together. It also specifies which user can log into this particular WebDAV share. If you don&#8217;t put <code>require user $USER</code> in there then anyone can log into anyone else&#8217;s share. That&#8217;s not good.
</p>
<h3>Fixing permissions</h3>
<p>
The problem with this setup as of now is that if you create a file from the mounted WebDAV folder in OS X it&#8217;s created as <code>www-data</code> and vice versus if you&#8217;re logged in via SSH.
</p>
<div class="alert">
<h4>Warning</h4>
<p>The following is an ugly hack, but it works. It should be used with caution and not trusted on production servers you truly care about.</p>
</div>
<pre><code>
#!/bin/sh

# Loop through all users and chmod/chown files and directories in $HOME/public_html
# I'm sure there is a better way of doing this.
for i in `ls /home`
do
    find /home/$i/public_html -type d -print -exec chown $i:www-data {} ;
    find /home/$i/public_html -type d -print -exec chmod 775 {} ;
    find /home/$i/public_html -type f -print -exec chown $i:www-data {} ;
    find /home/$i/public_html -type f -print -exec chmod 664 {} ;

    # I did this to keep users from editing their .htaccess
    chown root:root /home/$i/public_html/.htaccess
    chmod 644 /home/$i/public_html/.htaccess
done
</code></pre>
<p>
Set this up to run in <code>root</code>&#8216;s <code>cron</code> every minute. This will fix permission problems so that, after sixty or so seconds, you can edit files via SSH or your WebDAV mount.
</p>
<h3>Connecting to your WebDAV share from OS X</h3>
<ol>
<li>Open a Finder window </li>
<li>Hit <code>CMD+K</code> </li>
<li>Type in <code>https://my.server.com/~username</code> for the location</li>
<li>Click &#8220;Connect&#8221;</li>
<li>Click &#8220;Continue&#8221; when it asks about the boned SSL certificate (install a valid SSL certificate to avoid this annoyance)</li>
<li>Enter your username/password when prompted</li>
</ol>
<h3>Known Issues/Problems</h3>
<ol>
<li>Apache can read/write to all files in <code>$HOME/public_html</code></li>
<li>Apache can read <code>/etc/shadow</code></li>
<li>Requires a <code>cron</code> job to fix permissions</li>
<li>You lose the ability to have publicly accessible <code>http://www.mysite.com/~username</code> URLs</li>
</ol>
<h3>Conclusion</h3>
<p>
I&#8217;ve added <code>$HOME/www/www.joestump.net</code> along with my other sites and can now edit them through Finder or Term from my Macs at work and home. It&#8217;s all done over SSL and authentication is done via PAM, which means it&#8217;s fairly secure and easy to use. Personally, the few sacrifices are worth it to me to have this kind of setup. It also allows me to, say, save media files from work to home and vice versus in a pinch. I could also use various backup software, such as <code>rsync</code>, to sync and back up my various applications and data from computer to computer. Overall, I&#8217;m pleased with the outcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://stu.mp/2006/06/webdavsslpam-on-debianapache2.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached

 Served from: stu.mp @ 2013-06-18 16:37:34 by W3 Total Cache -->