<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Pablo&#039;s blog &#187; luks</title>
	<atom:link href="http://pupeno.com/tag/luks/feed/" rel="self" type="application/rss+xml" />
	<link>http://pupeno.com</link>
	<description>A bit of this, a bit of that and a lot about computers</description>
	<lastBuildDate>Wed, 15 Feb 2012 08:39:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pupeno.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/57ca76f9fb1bf9d10a9dd732ea88cc57?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Pablo&#039;s blog &#187; luks</title>
		<link>http://pupeno.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pupeno.com/osd.xml" title="Pablo&#039;s blog" />
	<atom:link rel='hub' href='http://pupeno.com/?pushpress=hub'/>
		<item>
		<title>Encrypted home in Ubuntu 8.10</title>
		<link>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-8-10/</link>
		<comments>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-8-10/#comments</comments>
		<pubDate>Sun, 10 Jun 2007 00:00:41 +0000</pubDate>
		<dc:creator>Pablo</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[cryptsetup]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[Kubuntu]]></category>
		<category><![CDATA[luks]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://328</guid>
		<description><![CDATA[This article is like a third edition to &#8220;Encrypted home in Ubuntu (or Kubuntu… or Debian…)&#8221;, although I keep changing the name. It&#8217;s the 8.10 edition. Many things changed and I updated the article for those, and the rest should work as well. Motivation Every day we put more and more personal information on our [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pupeno.com&amp;blog=8470507&amp;post=328&amp;subd=pupeno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article is like a third edition to &#8220;Encrypted home in Ubuntu (or Kubuntu… or Debian…)&#8221;, although I keep changing the name. It&#8217;s the 8.10 edition. Many things changed and I updated the article for those, and the rest should work as well.</p>
<h1>Motivation</h1>
<p>Every day we put more and more personal information on our computers, and our computers become lighter, smaller, more mobile. In other words, the importance of the information gets higher and the possibility of being loosed or stolen gets higher as well.</p>
<p><span id="more-328"></span></p>
<p>I think that if anyone gets a-hold of the information in my personal computer (s)he’d be able to impersonate me and make my life a mess. That’s why I like keeping all my information encrypted. That is, I have a separate partition for /home and it is encrypted.</p>
<p>The level of security for this scheme is not very high and if you are a real paranoid you should be reading some other tutorials. I am using just a pass-phrase for the encryption so I am susceptible to dictionary attacks, my swap is not encrypted, so some personal information would be available there. But that’s OK. I am not trying to protect from the people with enough sophistication to perform the needed operations to retrieve that information. Those are not many and they have other means.</p>
<p>My goal is to protect from the regular thieve or from loosing it… so I would mourn for some money being lost but I will sleep well at night.</p>
<p><strong>Disclaimer: the information will be encrypted, you’ll be able to access it with a key: a pass-phrase. If you loose it, you won’t be able to access than information again, so, be careful and make backups.</strong></p>
<h1>Installation</h1>
<p>You should install the operating system as you always do with a little detail: create the root partition, the swap partition and the home partition. But don&#8217;t assign any filesystem to the home partition, do not make or format it and do not set it as home.</p>
<p>After you did that you should be booting into a fresh system. Be sure not to store any sensitive information now, because it’ll be accessible to anyone. Some thinks to take care, if you use a browser or some instant messaging client, do not make them save the password, if you can avoid typing the passwords at all, that will be better.</p>
<p>Once you got pass that you’ll need two packages: cryptsetup and libpam-mount. You can install them with a command like:</p>
<pre>aptitude install cryptsetup libpam-mount</pre>
<p>During installation, limpam-mount request to convert the previous configuration. As we don&#8217;t really have a previous configuration, I&#8217;m not sure what it&#8217;s going to convert so I just choose &#8220;No&#8221; (the default) and let it install a fresh configuration.</p>
<h1>Partitioning</h1>
<p>The encryption we are going to use works like this. Linux puts a layer around a device and creates a new virtual device. Whatever is written to this new virtual device is written to the real device but encrypted. All this works at a very low level and it is called mapping. There are other kind of mappings (to perform other operations than encrypting… think for example as creating volumes of various partitions so they’d be seen as one).</p>
<p>To create the mapping run:</p>
<pre>sudo modprobe dm-crypt</pre>
<pre>sudo cryptsetup --verbose --verify-passphrase luksFormat /dev/sda6</pre>
<p>replacing /dev/sda6 with your particular (real) device.</p>
<p>A bit more about that command. cryptsetup is a program to create this encryption mappings. –-verbose is there because I like to see a lot of useless data and feel more geeky. –-verify-passphrase is there to be asked twice for the pass-phrase, so we don’t insert a wrong pass-phrase by accident. luksFormat is the action. luks is a new system that lets us have more than one password, change passwords, add passwords, etc to some encrypted device. Very handy.A complete execution of that command will look like:</p>
<pre>sudo cryptsetup --verbose --verify-passphrase luksFormat /dev/sda6

WARNING!
========
This will overwrite data on /dev/sda6 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.
</pre>
<h1>The new partition</h1>
<p>This new system, luks, also let us inspect what is in a luks-formatted partition. It works like this:</p>
<pre>sudo cryptsetup luksDump /dev/sda6
LUKS header information for /dev/sda6

Version:       	1
Cipher name:   	aes
Cipher mode:   	cbc-essiv:sha256
Hash spec:     	sha1
Payload offset:	1032
MK bits:       	128
MK digest:     	ff c3 22 a1 d1 fe 5e e4 e3 37 26 a7 8e 93 43 22 fa 83 c5 91
MK salt:       	27 59 46 c5 f2 21 5a 93 46 eb 2a cf 80 f1 46 95
               	b6 05 79 02 55 a4 49 33 87 d1 25 ae 49 74 40 b6
MK iterations: 	10
UUID:          	819cf83a-7c9b-49b8-9b74-e0d952aa1234

Key Slot 0: ENABLED
	Iterations:         	208350
	Salt:               	be 31 c7 e3 c9 a8 d5 37 09 12 34 e2 4a 3f a3 85
	                      	e0 fd bc 1e e4 3a fb d6 70 7c 7f 12 34 1a 6d 8e 43
	Key material offset:	8
	AF stripes:            	4000
Key Slot 1: DISABLED
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED</pre>
<p>Lot’s of nice information, don’t you feel super-geek ? You can see there that you have 8 spaces for pass-phrases, you have 8 slots of which you are using one, the 0.</p>
<p>To be able to access the encrypted partition you have to open it… and to do it you’ll need a key of course (your pass-phrase). We’ll see the mappings on /dev/mapper/, which should be empty by now (except for a control file… I wouldn’t name a mapping control, just in case):</p>
<pre>ls /dev/mapper/
control</pre>
<p>Ok! Now open it:</p>
<pre>sudo cryptsetup luksOpen /dev/sda6 home
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.</pre>
<p>Great! We have opened it. The last parameter, &#8220;home&#8221;, is the name of the mapping. Let’s take a look at the mappings:</p>
<pre>ls /dev/mapper/
control  home</pre>
<p>Good. This device file is like a partition itself. So, we’ll make a file-system in there in the same way you’d make it in sda6 (from now on, don’t do anything with sda6 except opening and other luks operations, your partition is /dev/mapper/home now). In my case I’ve picked ReiserFS, but you can use whatever you want:</p>
<pre>sudo mkfs.reiserfs -l home /dev/mapper/home
...lot's of geeky output...
ReiserFS is successfully created on /dev/mapper/home.</pre>
<p>and we are done. We can mount it:</p>
<pre>sudo mount /dev/mapper/home /media</pre>
<p>copy the current data (the home of a user and a couple of files):</p>
<pre>sudo cp -a /home/* /media/
cp: ne povas trovi stato-informon pri '/home/pupeno/.gvfs': Permeso rifuzita</pre>
<p>If you don&#8217;t speak the <a href="http://wikipedia.org/wiki/Esperanto">international language</a>, that mean: &#8220;cp: cannot stat `/home/pupeno/.gvfs&#8217;: Permission denied&#8221;. Everything seems to be OK anyway. Un-mount it:</p>
<pre>sudo umount /media/</pre>
<p>and close it:</p>
<pre>sudo cryptsetup luksClose home</pre>
<h1>Automagically mounting</h1>
<p>There are various ways to open and mount the encrypted file-system but after trying many different ones, this is the best one from my point of view. I like that it is not intrusive: when you log in, your user password will be used to open the file-system and it&#8217;ll be mounted automatically. Of course, then, the password of your user should match the pass-phrase in at least one of the slots of the encrypted device.</p>
<p>You need to modify /etc/pam.d/common-auth adding, at the end:</p>
<pre>@include common-pammount</pre>
<p>And /etc/pam.d/common-session to add that same line.</p>
<p>In /etc/security/pam_mount.conf.xml, around line 107 you have a list of &#8220;Linux encrypted home directory examples&#8221;, since what we are going to do is related to that it makes sense to put these lines after that comment (around line 183):</p>
<pre>
</pre>
<p>Of course replace &#8220;pupeno&#8221; with your username and &#8220;/dev/sda6&#8243; with your device. And that is the line that will make the magical mount happen.</p>
<p>Now just try it. It is very simple, log out, log in again and that’s it. You should have you newly super-encrypted home partition mounted. To check it out issue a mount command and among a huge amount of cryptic information you should see:</p>
<pre>/dev/mapper/_dev_sda6 on /home type reiserfs (rw)</pre>
<p>You can also list the files on /dev/mapper to find the _dev_sda6 mapping.</p>
<p>And that’s it, it wasn’t so hard, was it ?</p>
<h1>More users, more pass-phrases</h1>
<p>If there are more users add more lines to /etc/security/pam_mount.conf.xml, I haven’t tested it but it should work. Also just add more pass-phrases to the device using cryptsetup in this way:</p>
<pre>sudo cryptsetup luksAddKey /dev/sda6</pre>
<p>It’ll ask you for a current pass-phrase as well. This is also useful if you are changing pass-phrases, while you work on remembering the new one, don’t delete the old one, so if you forget the new one you should still be able to access your information with the old one. After you are confident of the new one, you can delete the old one with:</p>
<pre>sudo cryptsetup luksDelKey /dev/sda6 0</pre>
<p>where &#8220;0&#8243; is the slot where you have your old pass-phrase (hint: use luksDump). And here I want to remind you that if you lost the password you won’t be able to access the information. There’s no password recovery here: it is gone, forever, as scrambled, processed and destroyed as the dinner of Tuesday of the last week. Be very careful and always make backups.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pupeno.wordpress.com/328/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pupeno.wordpress.com/328/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pupeno.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pupeno.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pupeno.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pupeno.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pupeno.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pupeno.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pupeno.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pupeno.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pupeno.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pupeno.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pupeno.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pupeno.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pupeno.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pupeno.wordpress.com/328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pupeno.com&amp;blog=8470507&amp;post=328&amp;subd=pupeno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-8-10/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/931970b8dc51b72e05e3a12b88612d61?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Pablo</media:title>
		</media:content>
	</item>
		<item>
		<title>Encrypted home in Ubuntu (or Kubuntu… or Xubuntu…)</title>
		<link>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-or-kubuntu%e2%80%a6-or-xubuntu%e2%80%a6/</link>
		<comments>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-or-kubuntu%e2%80%a6-or-xubuntu%e2%80%a6/#comments</comments>
		<pubDate>Sun, 10 Jun 2007 00:00:16 +0000</pubDate>
		<dc:creator>Pablo</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[cryptsetup]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[Kubuntu]]></category>
		<category><![CDATA[luks]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://210</guid>
		<description><![CDATA[This article is like a second edition to Encrypted home in Ubuntu (or Kubuntu… or Debian…). Important changes include that I have tested it for Ubuntu 7.04 Feisty Fawn and it works, but the devices are sd instead of hd due to all hard disk being viewed as SCSI (I am not sure why). Also [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pupeno.com&amp;blog=8470507&amp;post=210&amp;subd=pupeno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article is like a second edition to Encrypted home in Ubuntu (or Kubuntu… or Debian…). Important changes include that I have tested it for Ubuntu 7.04 Feisty Fawn and it works, but the devices are sd instead of hd due to all hard disk being viewed as SCSI (I am not sure why). Also I corrected some text layout problems of the previous article and I am no longer targeting Debian. Since Debian 4.0 Etch encrypting the whole file system (but /boot) is trivial because it is supported on the install, so you are not likely going to need this. Also, it seems more and more Ubuntu is taking a different direction than Debian so we may start to find big differences and I am not going to test this on Debian.<span id="more-210"></span></p>
<h1>Motivation</h1>
<p>As we put more and more personal information on our computers or computers become lighter, small, more mobile. In other words, the importance of the information gets higher and the possibility of being loosed or stolen gets higher as well.</p>
<p>I think that if anyone gets a-hold of the information in my notebook (s)he’d be able to impersonate me and make my life a mess. That’s why I like keeping all my information encrypted. That is, I have a separate partition for /home and it is encrypted.</p>
<p>The level of security is not high and if you are a real paranoid you should be reading some other tutorials. I am using just a pass-phrase for the encryption so I am susceptible to dictionary attacks, my swap is not encrypted, so some personal information would be available there. But that’s Ok. I am not trying to protect from the people with enough sophistication to perform the needed operations to retrieve that information. And if the thing becomes really nasty I bet people can find other ways to access my information. My goal is to protect from the regular thieve or from loosing it… so I will mourn for some dollars being lost but I will sleep well at night.</p>
<p><strong>Disclaimer: the information will be encrypted, you’ll be able to access it with a key: a pass-phrase. If you loose it, you won’t be able to access than information again, so, be careful.</strong></p>
<h1>Installation</h1>
<p>You should install the operating system as you always do with a little detail: create the root partition, the swap partition but not the home partition. Leave some space for the home partition, we’ll create it latter.</p>
<p>After you did that you should be booting into a fresh system. Be sure not to store any sensitive information now, because it’ll be open to attacks. Some thinks to take care, if you use a browser or some instant messaging client, do not make them save the password, if you can avoid typing the passwords at all, that will be better.</p>
<p>Once you got pass that you’ll need two packages (in Ubuntu and Kubuntu, exactly this, in Debian probably too, in others you’ll have to figure it out; actually, this applies to all the document so I won’t repeat it again): cryptsetup and libpam-mount. You can install them with a command like:</p>
<pre>aptitude install cryptsetup libpam-mount</pre>
<h1>Partitioning</h1>
<p>Create the partition that will be your home partition. Do it in whatever way you prefer, I’ve personally use cfdisk a lot, but you can also use fdisk or any other partitioning tool. After that to ensure that the partition table is written and read by Linux reboot. Avoiding rebooting might not cause any problem or it may cause weird problems with error messages that are hard to understand and that made me loose an hour or so. So, be safe and reboot.</p>
<p>The encryption we are going to use works like this. Linux puts a layer around a device and creates a new virtual device. Whatever is written to this new virtual device is written to the real device but encrypted. All this works at a very low level and it is called mapping. There are other kind of mappings (to perform other operations than encrypting… think for example as creating volumes of various partitions so they’d be seen as one).</p>
<p>To create the mapping run:</p>
<pre>cryptsetup --verbose --verify-passphrase luksFormat /dev/sda3</pre>
<p>replacing /dev/sda3 with your particular (real) device. In my case sda1 is root and sda2 is swap. One important piece of advice here would be putting random information on /dev/sda3 so it is harder to guess what’s in there. I haven’t done it because I was working over some other encrypted partition which was created over random data… enough randomness for me. If you are working in a new or blank this putting the random data might be important. Using your favorite search-engine you can find how to do it in 30 seconds.</p>
<p>A bit more about that command. cryptsetup is a program to create this encryption mappings. –verbose is because we like to see a lot of useless data and feel more geeky. –verify-passphrase is to be asked twice for the pass-phrase, so we don’t insert a wrong pass-phrase by accident. luksFormat is the action. luks is a new system that lets us have more than one password, change passwords, add passwords, etc to some encrypted device. Very handy.</p>
<p><em>Update: I’ve recently installed Kubuntu in a MacBook Pro and I’ve had to modprobe aes (and possible modprobe dm-crypt too) before being able to run the following command line succesfuly, otherwise I’ve got this message:</em></p>
<pre>Failed to setup dm-crypt key mapping.
Check kernel for support for the aes-cbc-essiv:sha256 cipher spec and verify that /dev/sda5 contains at least 133 sectors.
Failed to write to key storage.
Command failed.</pre>
<p>A complete execution of that command will look like:</p>
<pre>WARNING!
========
This will overwrite data on /dev/sda3 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.
root@pulab:~#</pre>
<h1>The new partition</h1>
<p>This new system, luks, also let us inspect what is in a luks-formatted partition. It works like this:</p>
<pre>root@pulab:~# cryptsetup luksDump /dev/sda3
LUKS header information for /dev/sda3

Version:        1
Cipher name:    aes
Cipher mode:    cbc-essiv:sha256
Hash spec:      sha1
Payload offset: 1032
MK bits:        128
MK digest:      65 d9 47 47 f0 74 5c ad ae 79 03 6c c9 11 4d 56 b2 11 78 90
MK salt:        19 d7 3b c6 04 2d ee e1 77 c0 4b f1 ac e1 3a 21
                ce 02 10 9a c5 f7 5a b7 fd f5 d4 96 96 6d 79 0d
MK iterations:  10
UUID:           bf5ca0c3-a68f-4544-8840-ba2p2af98918

Key Slot 0: ENABLED
        Iterations:             70156
        Salt:                   08 e1 75 0e d1 1b 92 d1 f1 5f bd 50 9c ec a0 a2
                                b9 ea f8 da 1a 62 5d 4b 15 f3 4c a3 f3 49 12 83
        Key material offset:    8
        AF stripes:             4000
Key Slot 1: DISABLED
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED</pre>
<p>Lot’s of nice information, don’t you feel super-geek ? You can see there that you have 8 spaces for pass-phrases, you have 8 slots of which you are using one, the 0.</p>
<p>To be able to access the encrypted partition you have to open it… and to do it you’ll need a key of course (your pass-phrase). We’ll see the mappings on /dev/mapper/, which should be empty by now (except for a control file… I wouldn’t name a mapping control, just in case):</p>
<pre>root@pulab:~# ls /dev/mapper/
control</pre>
<p>Ok! Now open it:</p>
<pre>root@pulab:~# cryptsetup luksOpen /dev/sda3 home
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.</pre>
<p>Great! We have opened it. The last parameter, &#8220;home&#8221;, is the name of the mapping. Let’s take a look at the mappings:</p>
<pre>root@pulab:~# ls /dev/mapper/
control  home</pre>
<p>Good. This device file is like a partition itself. So, we’ll make a file-system in there in the same way you’d make it in sda3 (from now on, don’t do anything with sda3 except opening and other luks operations, your partition is /dev/mapper/home now). In my case I’ve picked reiserfs, but you can use whatever you want:</p>
<pre>root@pulab:~# mkfs.reiserfs -l home /dev/mapper/home
.
lot's of geeky output
.
root@pulab:~#</pre>
<p>and we are done. We can mount it:</p>
<pre>root@pulab:~# mount /dev/mapper/home /media/</pre>
<p>copy the current data (the home of a user and a couple of files):</p>
<pre>root@pulab:~# cp -a /home/* /media/</pre>
<p>un-mount it:</p>
<pre>root@pulab:~# umount /media/</pre>
<p>and close it:</p>
<pre>cryptsetup luksClose home</pre>
<h1>Automagically mounting</h1>
<p>There are various ways to open and mount the encrypted file-system but after trying many different ones, this is the best one from my point of view. I like that it is not intrusive: when you log in, your user password will be used to open the file-system and it’ll be mounted automatically. Of course then the password of your user should match the pass-phrase in some of the slots of the encrypted device.</p>
<p>You need to modify /etc/pam.d/common-auth adding, at the end:</p>
<pre>@include common-pammount</pre>
<p>And /etc/pam.d/common-session to add that same line:</p>
<pre>@include common-pammount</pre>
<p>In /etc/security/pam_mount.conf, around line 174 you have a list of &#8220;Linux encrypted home directory examples&#8221;, since what we are going to do is related to that it makes sense to put this line:</p>
<pre>volume pupeno crypt - /dev/sda3 /home cipher=aes - -</pre>
<p>there changing &#8220;pupeno&#8221; with your username and &#8220;/dev/sda3&#8243; with your device. And that is the line that will make the magical mount happen.</p>
<p>Now just try it. It is very simple, log out, log in again and that’s it. You should have you newly super-encrypted home partition mounted. To check it out issue a mount command and among a huge amount of cryptic information you should see:</p>
<pre>/dev/mapper/_dev_sda3 on /home type reiserfs (rw)</pre>
<p>You can also list the files on /dev/mapper to find the _dev_sda3 mapping.</p>
<p>And that’s it, it wasn’t so hard, was it ?</p>
<h1>More users, more pass-phrases</h1>
<p>If there are more users add more lines to /etc/security/pam_mount.conf, I haven’t tested it but it should work. Also just add more passphrases to the device using cryptsetup in this way:</p>
<pre>cryptsetup luksAddKey /dev/sda3</pre>
<p>It’ll ask you for a current pass-phrase as well. This is also useful if you are changing pass-phrases, while you work on remembering the new one, don’t delete the old one, so if you forget the new one you should still be able to access your information with the old one. After you are confident of the new one, you can delete the old one with:</p>
<pre>cryptsetup luksDelKey /dev/sda3 0</pre>
<p>where &#8220;0&#8243; is the slot where you have your old pass-phrase (hint: use luksDump). And here I want to remind you that if you lost the password you won’t be able to access the information. There’s no password recovery here: it is gone, forever, as scrambled, processed and destroyed as the dinner of Tuesday of the last week. Be very careful and always make backups.</p>
<h1>Comments on the original blog</h1>
<p><cite><a rel="external nofollow" href="http://borys.musielak.eu/en/">michuk</a> Says: </cite></p>
<p>Two more articles describing the same:<br />
* <a rel="nofollow" href="http://polishlinux.org/howtos/truecrypt-howto/">http://polishlinux.org/howtos/truecrypt-howto/</a><br />
* <a rel="nofollow" href="http://polishlinux.org/howtos/encrypted-home-partition-in-linux/">http://polishlinux.org/howtos/encrypted-home-partition-in-linux/</a></p>
<p><a href="http://pupeno.com/2007/06/10/encrypted-home-ubuntu/#comment-250">June 11th, 2007 at 5:47</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pupeno.wordpress.com/210/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pupeno.wordpress.com/210/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pupeno.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pupeno.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pupeno.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pupeno.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pupeno.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pupeno.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pupeno.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pupeno.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pupeno.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pupeno.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pupeno.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pupeno.wordpress.com/210/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pupeno.wordpress.com/210/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pupeno.wordpress.com/210/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pupeno.com&amp;blog=8470507&amp;post=210&amp;subd=pupeno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-or-kubuntu%e2%80%a6-or-xubuntu%e2%80%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/931970b8dc51b72e05e3a12b88612d61?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Pablo</media:title>
		</media:content>
	</item>
		<item>
		<title>Encrypted home in Ubuntu (or Kubuntu… or Debian…)</title>
		<link>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-or-kubuntu%e2%80%a6-or-debian%e2%80%a6/</link>
		<comments>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-or-kubuntu%e2%80%a6-or-debian%e2%80%a6/#comments</comments>
		<pubDate>Sun, 10 Jun 2007 00:00:14 +0000</pubDate>
		<dc:creator>Pablo</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[cryptsetup]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[Kubuntu]]></category>
		<category><![CDATA[luks]]></category>
		<category><![CDATA[privacy]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://202</guid>
		<description><![CDATA[The explanations you’ll find here have been tested with Ubuntu 6.10 (Edgy Eft) and Kubuntu 6.10 (Edgy Eft), they should work without any problem in other members of the Ubuntu family and with minimal changes in other Debian-based distributions like Debian itself or Mepis. In other distributions it might require even more changes. Motivation As [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pupeno.com&amp;blog=8470507&amp;post=202&amp;subd=pupeno&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The explanations you’ll find here have been tested with Ubuntu 6.10 (Edgy Eft) and Kubuntu 6.10 (Edgy Eft), they should work without any problem in other members of the Ubuntu family and with minimal changes in other Debian-based distributions like Debian itself or Mepis. In other distributions it might require even more changes.<br />
<span id="more-202"></span></p>
<h1>Motivation</h1>
<p>As we put more and more personal information on our computers or computers become lighter, small, more mobile. In other words, the importance of the information gets higher and the possibility of being loosed or stolen gets higher as well.</p>
<p>I think that if anyone gets a-hold of the information in my notebook (s)he’d be able to impersonate me and make my life a mess. That’s why I like keeping all my information encrypted. That is, I have a separate partition for /home and it is encrypted.</p>
<p>The level of security is not high and if you are a real paranoid you should be reading some other tutorials. I am using just a pass-phrase for the encryption so I am susceptible to dictionary attacks, my swap is not encrypted, so some personal information would be available there. But that’s Ok. I am not trying to protect from the people with enough sophistication to perform the needed operations to retrieve that information. And if the thing becomes really nasty I bet people can find other ways to access my information. My goal is to protect from the regular thieve or from loosing it… so I will mourn for some dollars being lost but I will sleep well at night.</p>
<p><strong>Disclaimer: the information will be encrypted, you’ll be able to access it with a key: a pass-phrase. If you loose it, you won’t be able to access than information again, so, be careful.</strong></p>
<h1>Installation</h1>
<p>You should install the operating system as you always do with a little detail: create the root partition, the swap partition but not the home partition. Leave some space for the home partition, we’ll create it latter.</p>
<p>After you did that you should be booting into a fresh system. Be sure not to store any sensitive information now, because it’ll be open to attacks. Some thinks to take care, if you use a browser or some instant messaging client, do not make them save the password, if you can avoid typing the passwords at all, that will be better.</p>
<p>Once you got pass that you’ll need two packages (in Ubuntu and Kubuntu, exactly this, in Debian probably too, in others you’ll have to figure it out; actually, this applies to all the document so I won’t repeat it again): cryptsetup and libpam-mount. You can install them with a command like:</p>
<pre>aptitude install cryptsetup libpam-mount</pre>
<h1>Partitioning</h1>
<p>Create the partition that will be your home partition. Do it in whatever way you prefer, I’ve personally use cfdisk a lot, but you can also use fdisk or any other partitioning tool. After that to ensure that the partition table is written and read by Linux reboot. Avoiding rebooting might not cause any problem or it may cause weird problems with error messages that are hard to understand and that made me loose an hour or so. So, be safe and reboot.</p>
<p>The encryption we are going to use works like this. Linux puts a layer around a device and creates a new virtual device. Whatever is written to this new virtual device is written to the real device but encrypted. All this works at a very low level and it is called mapping. There are other kind of mappings (to perform other operations than encrypting… think for example as creating volumes of various partitions so they’d be seen as one).</p>
<p>To create the mapping run:</p>
<pre>cryptsetup --verbose --verify-passphrase luksFormat /dev/hda3</pre>
<p>replacing /dev/hda with your particular (real) device. In my case hda1 is root and hda2 is swap. One important piece of advice here would be putting random information on /dev/hda3 so it is harder to guess what’s in there. I haven’t done it because I was working over some other encrypted partition which was created over random data… enough randomness for me. If you are working in a new or blank this putting the random data might be important. Using your favorite search-engine you can find how to do it in 30 seconds.</p>
<p>A bit more about that command. cryptsetup is a program to create this encryption mappings. –verbose is because we like to see a lot of useless data and feel more geeky. –verify-passphrase is to be asked twice for the pass-phrase, so we don’t insert a wrong pass-phrase by accident. luksFormat is the action. luks is a new system that lets us have more than one password, change passwords, add passwords, etc to some encrypted device. Very handy.</p>
<p>A complete execution of that command will look like:</p>
<pre>WARNING!
========
This will overwrite data on /dev/hda3 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Command successful.
root@pulab:~#</pre>
<h1>The new partition</h1>
<p>This new system, luks, also let us inspect what is in a luks-formatted partition. It works like this:</p>
<pre>root@pulab:~# cryptsetup luksDump /dev/hda3
LUKS header information for /dev/hda3

Version: 1
Cipher name: aes
Cipher mode: cbc-essiv:sha256
Hash spec: sha1
Payload offset: 1032
MK bits: 128
MK digest: 65 d9 47 47 f0 74 5c ad ae 79 03 6c c9 11 4d 56 b2 11 78 90
MK salt: 19 d7 3b c6 04 2d ee e1 77 c0 4b f1 ac e1 3a 21
ce 02 10 9a c5 f7 5a b7 fd f5 d4 96 96 6d 79 0d
MK iterations: 10
UUID: bf5ca0c3-a68f-4544-8840-ba2p2af98918

Key Slot 0: ENABLED
Iterations: 70156
Salt: 08 e1 75 0e d1 1b 92 d1 f1 5f bd 50 9c ec a0 a2
b9 ea f8 da 1a 62 5d 4b 15 f3 4c a3 f3 49 12 83
Key material offset: 8
AF stripes: 4000
Key Slot 1: DISABLED
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED</pre>
<p>Lot’s of nice information, don’t you feel super-geek ? You can see there that you have 8 spaces for pass-phrases, you have 8 slots of which you are using one, the 0.</p>
<p>To be able to access the encrypted partition you have to open it… and to do it you’ll need a key of course (your pass-phrase). We’ll see the mappings on /dev/mapper/, which should be empty by now (except for a control file… I wouldn’t name a mapping control, just in case):</p>
<pre>root@pulab:~# ls /dev/mapper/
control</pre>
<p>Ok! Now open it:</p>
<pre>root@pulab:~# cryptsetup luksOpen /dev/hda3 home
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.</pre>
<p>Great! We have opened it. The last parameter, &#8220;home&#8221;, is the name of the mapping. Let’s take a look at the mappings:</p>
<pre>root@pulab:~# ls /dev/mapper/
control home</pre>
<p>Good. This device file is like a partition itself. So, we’ll make a file-system in there in the same way you’d make it in hda3 (from now on, don’t do anything with hda3 except opening and other luks operations, your partition is /dev/mapper/home now). In my case I’ve picked reiserfs, but you can use whatever you want:</p>
<pre>root@pulab:~# mkfs.reiserfs -l home /dev/mapper/home
.
lot's of geeky output
.
root@pulab:~#</pre>
<p>and we are done. We can mount it:</p>
<pre>root@pulab:~# mount /dev/mapper/home /media/</pre>
<p>copy the current data (the home of a user and a couple of files):</p>
<pre>root@pulab:~# cp -a /home/* /media/</pre>
<p>un-mount it:</p>
<pre>root@pulab:~# umount /media/</pre>
<p>and close it:</p>
<pre>cryptsetup luksClose home</pre>
<h1>Automagically mounting</h1>
<p>There are various ways to open and mount the encrypted file-system but after trying many different ones, this is the best one from my point of view. I like that it is not intrusive: when you log in, your user password will be used to open the file-system and it’ll be mounted automatically. Of course then the password of your user should match the pass-phrase in some of the slots of the encrypted device.</p>
<p>You need to modify /etc/pam.d/common-auth adding, at the end:</p>
<pre>@include common-pammount</pre>
<p>And /etc/pam.d/common-session to add that same line:</p>
<pre>@include common-pammount</pre>
<p>In /etc/security/pam_mount.conf, around line 174 you have a list of &#8220;Linux encrypted home directory examples&#8221;, since what we are going to do is related to that it makes sense to put this line:</p>
<pre>volume pupeno crypt - /dev/hda3 /home cipher=aes - -</pre>
<p>there changing &#8220;pupeno&#8221; with your username and &#8220;/dev/hda3&#8243; with your device. And that is the line that will make the magical mount happen.</p>
<p>Now just try it. It is very simple, log out, log in again and that’s it. You should have you newly super-encrypted home partition mounted. To check it out issue a mount command and among a huge amount of cryptic information you should see:</p>
<pre>/dev/mapper/_dev_hda3 on /home type reiserfs (rw)</pre>
<p>You can also list the files on /dev/mapper to find the _dev_hda3 mapping.</p>
<p>And that’s it, it wasn’t so hard, was it ?</p>
<h1>More users, more passphrases</h1>
<p>If there are more users add more lines to /etc/security/pam_mount.conf, I haven’t tested it but it should work. Also just add more passphrases to the device using cryptsetup in this way:</p>
<pre>cryptsetup luksAddKey /dev/hda3</pre>
<p>It’ll ask you for a current pass-phrase as well. This is also useful if you are changing pass-phrases, while you work on remembering the new one, don’t delete the old one, so if you forget the new one you should still be able to access your information with the old one. After you are confident of the new one, you can delete the old one with:</p>
<pre>cryptsetup luksDelKey /dev/hda3 0</pre>
<p>where &#8220;0&#8243; is the slot where you have your old pass-phrase (hint: use luksDump). And here I want to remind you that if you lost the password you won’t be able to access the information. There’s no password recovery here: it is gone, forever, as scrambled, processed and destroyed as the dinner of Tuesday of the last week. Be very careful and always make backups.</p>
<h1>Comments in the original blog</h1>
<div><cite><a rel="external nofollow" href="http://www.codixx.de/polarizer.html"></a></cite></div>
<ol>
<li><cite><a rel="external nofollow" href="http://borys.musielak.eu/en/">michuk</a> Says: </cite><br />
Two more articles describing the same:<br />
* <a rel="nofollow" href="http://polishlinux.org/howtos/truecrypt-howto/">http://polishlinux.org/howtos/truecrypt-howto/</a><br />
* <a rel="nofollow" href="http://polishlinux.org/howtos/encrypted-home-partition-in-linux/">http://polishlinux.org/howtos/encrypted-home-partition-in-linux/</a></li>
</ol>
<p><a href="http://pupeno.com/blog/encrypted-home-ubuntu/#comment-250">June 11th, 2007 at 5:47</a> <a href="https://pupeno.com/wp-admin/post.php?action=editcomment&amp;comment=250">e</a></p>
<li>
<div><cite>Andrew Says: </cite></div>
<p>In Ubuntu 8.04, instead of editing /etc/security/pam_mount.conf you need to edit /etc/security/pam_mount.conf.xml and add something like</p>
<p>Make sure to add the line to /etc/crypttab:<br />
cryptohome /dev/devicename noauto luks</p>
<p>You wrote:<br />
And /etc/pam.d/common-session to add that same line:</p>
<p>48c77b0112e4613</p>
<p>this number should be<br />
@include common-pammount</p>
<p>as written above.</p>
<p><a href="http://pupeno.com/blog/encrypted-home-ubuntu/#comment-31061">September 10th, 2008 at 8:50</a> <a href="https://pupeno.com/wp-admin/post.php?action=editcomment&amp;comment=31061">e</a></p>
<div><!-- --></div>
<div>
<h5>Document Actions</h5>
</div>
</li>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pupeno.wordpress.com/202/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pupeno.wordpress.com/202/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pupeno.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pupeno.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pupeno.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pupeno.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pupeno.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pupeno.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pupeno.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pupeno.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pupeno.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pupeno.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pupeno.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pupeno.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pupeno.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pupeno.wordpress.com/202/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pupeno.com&amp;blog=8470507&amp;post=202&amp;subd=pupeno&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pupeno.com/2007/06/10/encrypted-home-in-ubuntu-or-kubuntu%e2%80%a6-or-debian%e2%80%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/931970b8dc51b72e05e3a12b88612d61?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Pablo</media:title>
		</media:content>
	</item>
	</channel>
</rss>
