<?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>Penguins in a Strange Land &#187; home</title>
	<atom:link href="http://strange.nsk.pt/tag/home/feed/" rel="self" type="application/rss+xml" />
	<link>http://strange.nsk.pt</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 26 Jul 2010 12:29:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Encrypted home filesystem with pam_mount</title>
		<link>http://strange.nsk.pt/2009/12/encrypted-home-filesystem-with-pam_mount/</link>
		<comments>http://strange.nsk.pt/2009/12/encrypted-home-filesystem-with-pam_mount/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 17:02:41 +0000</pubDate>
		<dc:creator>luciano</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[home]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[luks]]></category>
		<category><![CDATA[pam_mount]]></category>

		<guid isPermaLink="false">http://strange.nsk.pt/?p=64</guid>
		<description><![CDATA[There are several reasons for having an encrypted home partition. But usually, everyone should have it, if only for the reason that disks do go bad, and you don&#8217;t want to replace it and leave private data behind.
With that in mind, there are several options, depending in your operating system and security requirements. In this [...]]]></description>
			<content:encoded><![CDATA[<p>There are several reasons for having an encrypted home partition. But usually, everyone should have it, if only for the reason that disks do go bad, and you don&#8217;t want to replace it and leave private data behind.</p>
<p>With that in mind, there are several options, depending in your operating system and security requirements. In this howto I&#8217;ll be concentrating on <code>pam_mount</code>, using a LUKS encrypted partition. Probably limited to Linux, then. PAM works in many Unix systems, but LUKS may be restricted.</p>
<p>But before beginning, you have to choose between security and speed. By that, I mean choose an encryption and chaining algorithms. For the most security, I recommend <code>aes-xts-plain</code>, with <code>essiv:sha256</code> for IV calculation. For speed, though, on my netbook, I use <code>blowfish-ecb-plain</code>. Blowfish is slightly faster than AES, and not much less secure, but the ECB chaining mode is the fastest and very much insecure method. So choose wisely. Personally, my data isn&#8217;t that important, and if cryptanalysts are interested in it, there are better methods on getting the data: <a href="http://xkcd.com/538/">http://xkcd.com/538/</a></p>
<p>Now that you have chosen the algorithm, it&#8217;s time to encrypt your swap partition. That&#8217;s right, never forget the swap partition, where sensitive data may be swapped out to:</p>
<pre>echo 'swap /dev/sdaX /dev/urandom swap,cipher=blowfish-ecb-plain'
  &gt;&gt; /etc/crypttab
echo '/dev/mapper/swap    swap    swap    defaults    0 0' &gt;&gt; /etc/fstab</pre>
<p>Then reboot. Make sure you correct the swap device and replace the current entry in <code>/etc/fstab</code>.</p>
<p>Make a backup of your current home folder, or start from a clean state. Choose the partition you want your home to reside on, and format it as a LUKS device. First, however, you should zero the first megabyte or two, so that the detection code doesn&#8217;t mistake it as other filesystem:</p>
<pre>dd if=/dev/zero of=/dev/sdaY bs=16M count=1</pre>
<p>Take care to erase the correct device! And if it contained sensitive data, then remove the <code>count=1</code> and let it zero the full partition. Next, format it as LUKS. I&#8217;ll be using the less secure algorithm. When asked for a passphrase, enter your user&#8217;s.</p>
<pre>cryptsetup luksFormat /dev/sdaY --cipher blowfish-ecb-plain --key-size 128</pre>
<p>OK, you now have a device formated for encryption. Next step, activate it, and format a real filesystem on top:</p>
<pre>cryptsetup luksOpen /dev/sdaY enc</pre>
<p>This will create the device: <code>/dev/mapper/enc</code></p>
<p>For filesystem, choose what you will. I use <code>ext4</code>:</p>
<pre>mkfs.ext4 /dev/mapper/enc</pre>
<p>Then mount it, and restore your original data. Or start from scratch:</p>
<pre>mount /dev/mapper/enc /mnt
cp -a /etc/skell/.[[:alnum:]]* /mnt/
chown user: /mnt -R
umount /mnt</pre>
<p>Your home is ready! Unmount it, the job of mounting and unmounting will be done by <code>pam_mount</code>:</p>
<pre>umount /mnt
cryptsetup luksClose enc</pre>
<p>The preliminaries are done. You have your home in an encrypted device. Now, to configure <code>pajm_mount</code> for automatically mount and unmount it.</p>
<p>Make sure you have <code>pam_mount</code> installed in your system. The package is called like the name in Fedora, and <code>libpam-mount</code> in Debian/Ubuntu. The configuration file is <code>/etc/security/pam_mount.conf.xml</code>, read it, and disable any limitation you&#8217;re interested in. Add a line for your user:</p>
<pre>&lt;volume user="luciano" path="/dev/sdaY" mountpoint="~" options="" /&gt;</pre>
<p>Note the empty <code>options</code> key, otherwise some default options may get in your way. Try either way. If you didn&#8217;t zero the device, and it gets detected as something else than a LUKS device, then add <code>fstype="crypt_LUKS"</code> to the line. You can see what it is detected as with:</p>
<pre># blkid /dev/sdaY
/dev/sdaY: UUID=".." SEC_TYPE="ext2" TYPE="ext3"</pre>
<p>If it doesn&#8217;t say LUKS, then you must add the <code>fstype</code> definition.</p>
<p><code>pam_mount</code> is now set up. Next, configure PAM to use it. There are some particularities for <code>pam_mount</code>, especially because GDM may try to start daemons as your user before you get your home mounted. Created a configuration file that will be include by other PAM-aware services, defining <code>pam_mount</code></p>
<pre>echo '
auth	optional	pam_mount.so
session	optional	pam_mount.so
' &gt;&gt; /etc/pam.d/system-mount</pre>
<p>Now, depending on your current PAM configuration, you may get away with doing the following steps only to the <code>/etc/pam.d/system-auth</code> or other generic file, included by services&#8217; definitions. But that is not the case for Fedora 11, and do make sure all services include the generic file first.<br />
In my case, I changed the files:</p>
<ul>
<li><code>/etc/pam.d/sshd</code></li>
<li><code>/etc/pam.d/login</code></li>
<li><code>/etc/pam.d/gdm-password</code></li>
</ul>
<p>Now, add the following line as the first <strong>auth</strong> definition, or as the definition immediately after an <code>selinux</code> <strong>permit</strong> or <strong>close</strong> action:</p>
<pre>auth        include       system-mount</pre>
<p>Also, for <strong>session</strong>, respecting the <code>selinux</code> thingy:</p>
<pre>session     include       system-mount</pre>
<p>Now try logging in as the user in a console, or via ssh. You should see the prompt for password as: <code>pam_mount password:</code><br />
If it works, then try a graphical login. Console is easier, a graphical login may get <code>dbus</code> or <code>keyring</code> programs running before the pam_mount is run, but you&#8217;ll prevent that by having the <code>system-mount</code> lines as the first ones.</p>
]]></content:encoded>
			<wfw:commentRss>http://strange.nsk.pt/2009/12/encrypted-home-filesystem-with-pam_mount/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
