Encrypted partitions with linux Loop-AES and GPG
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
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.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.-
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 withchmod 400 key.asc
. 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.At the first time we format the partition that is now available:
mkfs.ext3 /dev/loop0
Now the partition is useable after a normal mount:
mount /dev/sda1 /mnt/crypto
-
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
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.
Embassies
-
Und soviiiel Aufwand für ein bisschen Bit-geschupse
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-) -
Das mit der Aufwand sagt gerade derjenige, der Kryptograph werden will.
@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ö. -
nur so einer darf sowas auch sagen
@{@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. -
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
scheinbar nur milch .. :|
für mehr kreativität in sicherheits captchas die eigentlich keine captchas sind!! -
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
*Milch* -
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.
N8
Phil -
ja scheint so als hätte wir keine Wahl
PS:
finde ja das "erlaubte Begriff_e_" schon etwas übertrieben ist -
Es sind genau zwei Begriffe, von daher darf man vom Plural sprechen. Zurück
-
pfff...
Zwei Sprachen. Ein Begriff. Doppel -
Sehe ich nicht so, da diese Whitelist sprachunabhängig ist und damit sind es zwei Begriffe.
-
Ui ist des lustig, kaum hast du nen Kommentarfeed diskutieren wir sogar über deinen Blog über so Sinnfreie sachen
*Milk* -
Sinnfrei schreibt man klein!
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
Commenting isn't available anymore.
Trackback(s)
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/