Daten in Dateien Verschlüsseln mit LUKS / Encrypt Data in Files with LUKS (DE / EN)

in #deutsch3 years ago

(English Below / Englisch unten)

Daten in Dateien Verschlüsseln mit LUKS

Wie schon hier hier beschrieben, wenn man auf einem Linux System verschlüsselte Dateisysteme Anlegen will ist das LUKS Format die erste Wahl. Will man einen Luks Container in einer Datei anlegen dann ist die Vorgehensweise etwas anders als für USB Sticks/Festplatten.Das sieht dann so aus:


1 . Zuerst muss die Datei erstellt werden, hier z.b 43GB Gross

dd if=/dev/zero of=./encrypt-data.bin bs=512  count=89478485

2 . Erstellen des LUKS Containers in der Datei

cryptsetup -s 512 luksFormat --type luks2 ./encrypt-data.bin

3 . Mounten des LUKS Containers

cryptsetup open ./encrypt-data.bin cryptroot

4 . Erstellen/Formatieren eines Dateisystems innerhalb des LUKS Containers

mkfs -t ext4 /dev/mapper/cryptroot

5 . Mounten des inneren Dateisystems

mount /dev/mapper/cryptroot /mnt

Jetzt kann ganz normal auf das innere Dateisystem Zugregriffen, Daten Kopiert werden usw.

6 . Unmounten des inneren Dateisystems:

umount /mnt

7 . Schliessen des LUKS Containers

cryptsetup close cryptroot





Grundsätzlich ist es möglich für einen LuksContainer 8 Passwörter bzw Keyfiles zu vergeben. Realisiert wird das über sogenannte "Slots". In jedem Slot kann ein Passwort bzw KeyFile eingetragen werden. Die Slots müssen einzeln geändert werden. Beim Anlegen eines LUKS Containers muss ein Passwort oder Keyfile vergeben werden. Die weiteren 7 sind Optional.
Mittels:

cryptsetup luksDump /dev/sdc1

kann man die luks Headerdaten auslesen. Darin wird dann auch angezeigt wieviele
Slots bereits verwendet werden bzw wieviele Passwörter und Keyfiles

Hinzugefügt werden kann ein weiteres Passwort/KeyFile mit:

cryptsetup luksAddKey ./encrypt-data.bin

Hierbei wird der nächste freie Slot verwendet. Möchte man das Passwort in einem bestimmten Slot (hier der sechste) hinzufügen:

cryptsetup luksAddKey ./encrypt-data.bin -S 6

Das ändern eines bestehenden Passworts ist nur möglich wenn das vorhergehende Passwort bekannt ist:

cryptsetup luksChangeKey ./encrypt-data.bin

Um Passwörter/Keyfiles zu Löschen gibt es 2 Möglichkeiten:
1 . Löscht jeden Key der dem eingegebenen Passwort/KeyFile entspricht

cryptsetup luksRemoveKey ./encrypt-data.bin

2 . Löscht den Key im angegebenen Slot

cryptsetup luksKillSlot encrypt-date.bin 6

English Version

Encrypt Data in Files with LUKS

As already described here, if you want to create encrypted file systems on a Linux system, the LUKS format is the first choice. If you want to create a LUKS container in a file then the procedure is slightly different than for USB sticks/hard drives.this looks like this:


1 . first the file must be created, here e.g. 43GB large

dd if=/dev/zero of=./encrypt-data.bin bs=512 count=89478485

2 . create the LUKS container in the file

cryptsetup -s 512 luksFormat --type luks2 ./encrypt-data.bin

3 . mounting the LUKS container

cryptsetup open ./encrypt-data.bin cryptroot

4 . create/format a file system inside the LUKS container

mkfs -t ext4 /dev/mapper/cryptroot

5 . mount the inner filesystem

mount /dev/mapper/cryptroot /mnt

Now the inner file system can be accessed normally, data can be copied etc.

6 . unmount the inner file system:

umount /mnt

7 . closing the LUKS container

cryptsetup close cryptroot





In principle it is possible to assign 8 passwords or keyfiles for one LuksContainer. This is realized via so-called "slots". A password or keyfile can be entered in each slot. The slots must be changed individually. When creating a LUKS container, one password or keyfile must be assigned. The other 7 are optional.
By means of:

cryptsetup luksDump ./encrypt-data.bin

you can read the luks header data. This will also show how many
slots are already used and how many passwords and keyfiles are used.

You can add another password/keyfile with:

cryptsetup luksAddKey ./encrypt-data.bin

Here the next free slot is used. If you want to add a password in a certain slot (here the sixth):

cryptsetup luksAddKey ./encrypt-data.bin -S 6

Changing an existing password is only possible if the previous password is known:

cryptsetup luksChangeKey ./encrypt-data.bin

To delete passwords/keyfiles there are 2 possibilities:
1 . deletes every key that corresponds to the entered password/KeyFile

cryptsetup luksRemoveKey ./encrypt-data.bin

2 . deletes the key in the specified slot

cryptsetup liksKillSlot encrypt-date.bin 6
Sort:  

Du hast ein Upvote von mir bekommen, diese soll die Deutsche Community unterstützen. Wenn du mich unterstützten möchtest, dann sende mir eine Delegation. Egal wie klein die Unterstützung ist, Du hilfst damit der Community. DANKE!

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.028
BTC 56758.93
ETH 3033.46
USDT 1.00
SBD 2.30