{"id":22,"date":"2006-11-08T21:15:15","date_gmt":"2006-11-08T19:15:15","guid":{"rendered":"http:\/\/blogs.igalia.com\/berto\/2006\/11\/08\/disk-encryption-in-linux-iv-encrypting-a-full-partition-with-luks\/"},"modified":"2006-11-08T21:15:15","modified_gmt":"2006-11-08T19:15:15","slug":"disk-encryption-in-linux-iv-encrypting-a-full-partition-with-luks","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/berto\/2006\/11\/08\/disk-encryption-in-linux-iv-encrypting-a-full-partition-with-luks\/","title":{"rendered":"Disk encryption in Linux (IV): Encrypting a full partition with LUKS"},"content":{"rendered":"<p><a href=\"http:\/\/luks.endorphin.org\/\">LUKS<\/a> is a hard disk encryption standard for Linux created by Clemens Fruhwirth. Althought the reference implementation is based on <a href=\"http:\/\/www.saout.de\/misc\/dm-crypt\/\">dm-crypt<\/a>, it has several improvements over plain dm-crypt (as seen in the third post in this series), including support for multiple keys and passphrase revocation.<\/p>\n<p>To use LUKS you&#8217;ll need a recent <em>cryptsetup<\/em> package (Debian sarge users can get it from <a href=\"http:\/\/backports.org\/\">backports.org<\/a>). You will also need an empty partition to encrypt. You should fill it with random data before beginning:<\/p>\n<pre>\n$ shred -v \/dev\/hdaX\n<\/pre>\n<p>Now you have to initialize that partition with LUKS:<\/p>\n<pre>\n$ cryptsetup luksFormat \/dev\/hdaX\n<\/pre>\n<p>A random key will be generated and you will be asked a passphrase to encrypt it. Now you can <em>decrypt<\/em> your newly created LUKS partition and begin to use it:<\/p>\n<pre>\n$ cryptsetup luksOpen \/dev\/hdaX myname\n<\/pre>\n<p>Here, <tt>myname<\/tt> is the name of the device that will be created under <tt>\/dev\/mapper<\/tt>. Now it&#8217;s time to create a filesystem:<\/p>\n<pre>\n$ mke2fs \/dev\/mapper\/myname\n<\/pre>\n<p>Now you can mount and use <tt>\/dev\/mapper\/myname<\/tt> just like any other filesystem. When you&#8217;re done, unmount it and <em>close<\/em> the LUKS device so it won&#8217;t be accessible anymore until you open it again:<\/p>\n<pre>\n$ cryptsetup luksClose myname\n<\/pre>\n<p>So far so good, but how do you mount that partition automatically on boot? Just put this in your <tt>\/etc\/crypttab<\/tt> (and don&#8217;t forget to add <tt>\/dev\/mapper\/myname<\/tt> to your <tt>\/etc\/fstab<\/tt> file!):<\/p>\n<pre>\nmyname    \/dev\/hdaX    none    luks,check=ext2\n<\/pre>\n<p><tt>myname<\/tt> is the encrypted device that will appear under <tt>\/dev\/mapper<\/tt> and <tt>\/dev\/hdaX<\/tt> is the original device.<\/p>\n<p>The third field, <tt>none<\/tt>, means that the key to decrypt the filesystem is not stored anywhere, so <em>cryptsetup<\/em> will ask you during boot.<\/p>\n<p>The fourth field lists misc options: <tt>luks<\/tt> means that the partition is encrypted with LUKS format (as opposed to plain dm-crypt format). <tt>check=ext2<\/tt> will make <em>cryptsetup<\/em> look for an ext2\/ext3 filesystem on the decrypted partition. That way, <em>cryptsetup<\/em> will notice whether you introduced the right passphrase and ask it again in case you typed it incorrectly. There are several partition checks (not just ext2), and you can write your own scripts. Just have a look at <tt>\/lib\/cryptsetup\/checks\/<\/tt>.<\/p>\n<p>And that&#8217;s all for the basic usage, but there are some other nice things that you can do, such as adding more valid passphrases to a LUKS partition:<\/p>\n<pre>\n$ cryptsetup luksAddKey \/dev\/hdaX\n<\/pre>\n<p>You can see some information about the partition (including the number of valid passphrases available):<\/p>\n<pre>\n$ cryptsetup luksDump \/dev\/hdaX\n<\/pre>\n<p>And obviously you can remove any passphrase:<\/p>\n<pre>\n$ cryptsetup luksDelKey \/dev\/hdaX slot\n<\/pre>\n<p>Where <em>slot<\/em> is the number of the key slot you want to remove (you can see it with <tt>luksDump<\/tt>).<\/p>\n<p>And that&#8217;s enough by now. As you can see, it&#8217;s not that hard to keep your data secure. Keep in mind, however, that encrypting a whole partition introduces some extra overhead, so your system will be slower. You don&#8217;t have to encrypt everything (i.e. under <tt>\/usr<\/tt> you probably don&#8217;t have any confidential data). Choose wisely and enjoy!.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LUKS is a hard disk encryption standard for Linux created by Clemens Fruhwirth. Althought the reference implementation is based on dm-crypt, it has several improvements over plain dm-crypt (as seen in the third post in this series), including support for multiple keys and passphrase revocation. To use LUKS you&#8217;ll need a recent cryptsetup package (Debian [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,9,10,12],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-english","category-gpul","category-igalia","category-free-software"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":0,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/berto\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}