Aktion “Stoppt die Vorratsdatenspeicherung”

Willst du auch bei der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:
Thursday, 18. October 2007 - 22:09

Encrypted partitions with linux Loop-AES and GPG

Dieser Beitrag ist auch in deutsch verfügbar (empfohlen).

Yeah, yesterday I had a real linux hacking session again. This time I wanted to store data encrypted on an external hard drive. The target was to find a way that is really comfortable without having to remind a reeeeally long password. Especially when you already have a GPG-key pair you don't have to remember another password.
This is just a quick tutorial. For a more verbose howto have a look for Loop-AES tutorial at riseup labs.

Prerequisites

You need a hard drive that is currently empty. This should be already partitioned. If it isn't, now you have the change to take your favorite partitioner and do it quickly. If you want to encrypt data on an already existing partition, let me say, that it is possible (with dd), but this tutorial doesn't cover this purpose.

The paket util-linux must be installed, too. If you're using a binary distribution it's usually safe to assume, that all crypto function are included. If you are compiling the paket by yourself, pleake make sure to configure with crypto support. On Gentoo Linux you can do that by setting the USE-Flag “crypt”

You also need GPG and an already generate key-pair.

Let's go

  1. At first you have to check, if your kernel knows the crypto-algorithm we want to use. In our case it's AES256. To do this it's the best to call make menuconfig in your Linux sources directory (usually at /usr/src/linux). Please check if the following menu point is active: Cryptographic options → AES cipher algorithms.

  2. Additionally the packet Loop-AES must be installed. It's the best if you use the software installation tools of your distribution. On Gentoo an emerge loop-aes is enough.

  3. After that you have generate the password, with that the hard drive is protected. You don't have to remind this password, because we store it in a file that we encrypt with GPG. So you generate a password that is as long as possible. I used apg for that (apg -a 1 -n 1 -m 23 -x 65 | gpg --symetric -a > key.asc). You can also use the random devices directly, like this tutorial recommends.

    The generated file should be moved to another device, that is physically seperated from the crypted device. If you want to encrypt a partition of an interal hard drive, it proffers that you use an USB stick for the key file. If the target is an external drive, you can store the file on the internal hard drive. Or on a Smartcard. Or a CD. Somewhere. The main thing is to move it away from the target device.
    After that you should absolutely protect your keyfile with chmod 400 key.asc.

  4. Now you can connect the physical device with the loop device, that is doing the encryption transparently. That works with the command losetup: losetp -e AES256 -K /path/to/your/key.asc /dev/loop0 /dev/sda1. Then the operating system asks for your GPG passphrase.

  5. At the first time we format the partition that is now available: mkfs.ext3 /dev/loop0

  6. Now the partition is useable after a normal mount: mount /dev/sda1 /mnt/crypto

  7. To make the whole thing most comfortably, I recommend a fitting entry in the fstab:
    /dev/sda1 /mnt/crypto ext3 user,noauto,loop=/dev/loop0,encryption=AES256,gpgkey=/path/to/your/key.asc 0 0

  8. At the end the partition can be used like any other normal partition: mount, use, unmount. Merely the input of the passphrase comes along. It will be really nice, when combine it with some udev rules and an automounter.

Filed under: Geek stuff
Technorati Tags:

Embassies

  1. Manu (Website) wrote at 19/10/07 - 11:57:32
    Und soviiiel Aufwand für ein bisschen Bit-geschupse (Smiley: bare one's tongue) (Smiley: bare one's tongue) (Smiley: bare one's tongue)
    sorry, ich bin grad irgendwie net ganz ausgeglichen.

    BTW:
    Ein Smitley-wähler wär cool.Den vermiss bei Wordpress auch ein bischen.

    BTWBTW:
    Für den creativen Leser wäre es bestimmt noch toll, sowas wie Anagramme von "Milch" oder ähnliches als Spamschutzantwort durchgehen zu lassen.

    BTWBTWBTW:
    am besten diesen Kommentar einfach ignorieren B-)
  2. Philipp Söhnlein (Website) wrote at 19/10/07 - 13:18:17
    Das mit der Aufwand sagt gerade derjenige, der Kryptograph werden will. (Smiley: wink)

    @BTW1: Das steht schon seit ewigen Zeiten auf der 2do Liste.
    Aber du sagst, das gibt es nicht für WP? Kann ich mir nicht vorstellen, das es da gar kein Plugin für gibt. Ich glaube du bringst mich da auf ne Idee...

    @BTW2: Du meinst hauptsache der String ist 5 Zeichen lang und es kommen die Buchstaben m, i, l, c und h genau einmal vor?

    @BTW3: Nö. (Smiley: bare one's tongue)
  3. Manu (Website) wrote at 19/10/07 - 13:49:34
    nur so einer darf sowas auch sagen (Smiley: grin)

    @{@BTW1}: zumindest nicht bei Wordpress.com wo man keine eigenen Plugins reinsetzen kann.

    @{@BTW2}: na klar das beschäftigt, würde ich sagen^^

    @{@BTW3}: verdammt.
  4. Puddy wrote at 21/10/07 - 17:30:06
    hey das fänd ich auch cool, ich komm mir langsam blöd vor da immer milch reinzuschreiben,
    hab schon "immernoch milch" oder "kuhfladen" probiert, geht aber alles nicht (Smiley: sad)
    scheinbar nur milch .. :|

    für mehr kreativität in sicherheits captchas die eigentlich keine captchas sind!!
  5. Manu (Website) wrote at 21/10/07 - 18:26:41
    finde das auch so... kategorisch. Man gibt Milch ein, meint aber Kuhmilch. Und selbst KuhMilch ist doch nicht gleich KuhMilch. wo kommen wir denn da hin.


    Haha 2 gegen 1, ich liebe die Blogosphäre - jetzt hast du keine Wahl mehr (Smiley: wink)

    *Milch*
  6. Philipp Söhnlein (Website) wrote at 23/10/07 - 22:52:41
    Ach Leute, ihr erwartet nicht wirklch, dass ich jetzt die Whitelist erweitere, weil die momentan erlaubten Begriffe zu langweilig sind?
    Irgendwie wiederspräche das ja auch dem Whitelisting-Gedanken. Kann ich ja gleich * erlauben. (Smiley: wink)

    N8
    Phil
  7. Manu (Website) wrote at 24/10/07 - 10:35:37
    ja scheint so als hätte wir keine Wahl (Smiley: sad)

    PS:
    finde ja das "erlaubte Begriff_e_" schon etwas übertrieben ist (Smiley: bare one's tongue)

  8. Philipp Söhnlein (Website) wrote at 24/10/07 - 11:06:29
    Es sind genau zwei Begriffe, von daher darf man vom Plural sprechen. Zurück (Smiley: bare one's tongue)
  9. Manu (Website) wrote at 24/10/07 - 16:33:57
    pfff...

    Zwei Sprachen. Ein Begriff. Doppel (Smiley: bare one's tongue)
  10. Philipp Söhnlein (Website) wrote at 24/10/07 - 16:51:57
    Sehe ich nicht so, da diese Whitelist sprachunabhängig ist und damit sind es zwei Begriffe.
  11. Manu (Website) wrote at 24/10/07 - 17:12:05
    Ui ist des lustig, kaum hast du nen Kommentarfeed diskutieren wir sogar über deinen Blog über so Sinnfreie sachen (Smiley: grin)

    *Milk*
  12. Philipp Söhnlein (Website) wrote at 24/10/07 - 22:21:21
    Sinnfrei schreibt man klein! (Smiley: bare one's tongue)

    Naja, irgendwie bist du nie im IM online wenn ich es bin. Wahrscheinlich ist es umgekehrt genauso. Deshalb verschieben wir unseren Drang nach hochwertigen Diskussionen wohl unterbewusst in das Blog hier.

    Aber so langsam sollten wir uns nen anderen Ort suchen, wird arg Offtopic hier.

    Ciao
    Phil

Comment entry

Advice:
Commenting isn't available anymore.

Trackback(s)

What's trackback?

A trackback is a kind of a source link. If i was finding an interesting entry in another blog, that i am commenting in my own blog, i am linking to the original message via the trackback. Has someone commented one of my entries in his/her weblog, you can find this link here under trackbacks, too. More informations about trackback are in the Wikipedia for example.

Trackback URL: /trackback/encrypted-partitions-with-linux-loop-aes-and-gpg/

Trackbacks aren't available anymore.

There are no trackbacks for this entry.

Sidebar

Recent acoustic enchantment

Clare Burson - Love Me In The Morning

Random Thought

Unix IS user friendly. It's just selective about who its friends are.

Change the emotion

Firefox Add to Technorati Favorites