LUKS – Verschlüsselte Datenfestplatte: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| (18 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 14: | Zeile 14: | ||
= Voraussetzungen = | = Voraussetzungen = | ||
| − | * apt-get install cryptsetup | + | * apt-get install cryptsetup cryptsetup-initramfs |
= Partition anlegen = | = Partition anlegen = | ||
| Zeile 36: | Zeile 36: | ||
<pre> | <pre> | ||
Device Boot Start End Sectors Size Id Type | Device Boot Start End Sectors Size Id Type | ||
| − | /dev/sdb1 2048 | + | /dev/sdb1 2048 41943039 41940992 20G 83 Linux |
</pre> | </pre> | ||
= LUKS-Container erstellen = | = LUKS-Container erstellen = | ||
| − | * cryptsetup luksFormat | + | * cryptsetup luksFormat /dev/sdb1 |
<pre> | <pre> | ||
WARNING! | WARNING! | ||
| Zeile 51: | Zeile 51: | ||
Verify passphrase: | Verify passphrase: | ||
</pre> | </pre> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
= LUKS-Container öffnen = | = LUKS-Container öffnen = | ||
| − | * cryptsetup open /dev/sdb1 | + | * cryptsetup open /dev/sdb1 cryptdata |
Enter passphrase for /dev/sdb1: | Enter passphrase for /dev/sdb1: | ||
| Zeile 80: | Zeile 69: | ||
= Manuell einhängen (Test) = | = Manuell einhängen (Test) = | ||
| − | * mount /dev/mapper/ | + | * mount /dev/mapper/cryptdata /mnt/data |
* df -h /mnt/data | * df -h /mnt/data | ||
<pre> | <pre> | ||
| − | Filesystem | + | Filesystem Size Used Avail Use% Mounted on |
| − | /dev/mapper/ | + | /dev/mapper/cryptdata 20G 2.1M 19G 1% /mnt/data |
</pre> | </pre> | ||
Zum Testen wieder aushängen: | Zum Testen wieder aushängen: | ||
* umount /mnt/data | * umount /mnt/data | ||
| − | * cryptsetup close | + | * cryptsetup close cryptdata |
= Automatisch einhängen beim Systemstart = | = Automatisch einhängen beim Systemstart = | ||
| Zeile 96: | Zeile 85: | ||
* blkid /dev/sdb1 | * blkid /dev/sdb1 | ||
| − | + | /dev/sdb1: UUID="eab7be99-90d8-4986-88a7-bdfb9d7ff502" TYPE="crypto_LUKS" PARTUUID="89a985e7-01" | |
| − | /dev/sdb1: UUID=" | ||
| − | |||
== /etc/crypttab == | == /etc/crypttab == | ||
| − | + | Trägt den LUKS-Container ein, damit er beim Booten geöffnet wird: | |
| − | + | cryptdata UUID=eab7be99-90d8-4986-88a7-bdfb9d7ff502 none luks,initramfs | |
{| class="wikitable" | {| class="wikitable" | ||
| Zeile 110: | Zeile 97: | ||
! Feld !! Bedeutung | ! Feld !! Bedeutung | ||
|- | |- | ||
| − | | <code> | + | | <code>cryptdata</code> || Name des Mappers unter <code>/dev/mapper/</code> |
|- | |- | ||
| <code>UUID=...</code> || UUID der verschlüsselten Partition | | <code>UUID=...</code> || UUID der verschlüsselten Partition | ||
| Zeile 117: | Zeile 104: | ||
|- | |- | ||
| <code>luks</code> || Format-Typ | | <code>luks</code> || Format-Typ | ||
| + | |- | ||
| + | | <code>initramfs</code> || Container wird bereits im initramfs geöffnet – stellt sicher, dass die Passwortabfrage beim Boot erscheint | ||
|} | |} | ||
| Zeile 123: | Zeile 112: | ||
Hängt das Dateisystem nach dem Öffnen ein: | Hängt das Dateisystem nach dem Öffnen ein: | ||
| − | /dev/mapper/ | + | /dev/mapper/cryptdata /mnt/data ext4 defaults 0 2 |
| + | |||
| + | == Update Ramdisk == | ||
| + | |||
| + | * update-initramfs -u | ||
= Systemstart = | = Systemstart = | ||
| + | |||
| + | Please unlock disk cryptdata: | ||
Beim nächsten Booten erscheint eine Passwortabfrage für <code>/dev/sdb1</code>. | Beim nächsten Booten erscheint eine Passwortabfrage für <code>/dev/sdb1</code>. | ||
Nach korrekter Eingabe wird <code>/mnt/data</code> automatisch eingehängt. | Nach korrekter Eingabe wird <code>/mnt/data</code> automatisch eingehängt. | ||
| − | |||
| − | |||
= Ergebnis prüfen = | = Ergebnis prüfen = | ||
| Zeile 136: | Zeile 129: | ||
* df -h /mnt/data | * df -h /mnt/data | ||
<pre> | <pre> | ||
| − | Filesystem | + | Filesystem Size Used Avail Use% Mounted on |
| − | /dev/mapper/ | + | /dev/mapper/cryptdata 20G 2.1M 19G 1% /mnt/data |
</pre> | </pre> | ||
| − | * cryptsetup status | + | * cryptsetup status cryptdata |
<pre> | <pre> | ||
| − | /dev/mapper/ | + | /dev/mapper/cryptdata is active and is in use. |
type: LUKS2 | type: LUKS2 | ||
cipher: aes-xts-plain64 | cipher: aes-xts-plain64 | ||
| Zeile 162: | Zeile 155: | ||
| <code>cryptsetup luksChangeKey /dev/sdb1</code> || Passwort ändern | | <code>cryptsetup luksChangeKey /dev/sdb1</code> || Passwort ändern | ||
|- | |- | ||
| − | | <code>cryptsetup open /dev/sdb1 | + | | <code>cryptsetup open /dev/sdb1 cryptdata</code> || Container manuell öffnen |
|- | |- | ||
| − | | <code>cryptsetup close | + | | <code>cryptsetup close cryptdata</code> || Container manuell schließen |
|} | |} | ||
Aktuelle Version vom 16. Mai 2026, 13:22 Uhr
LUKS – Verschlüsselte Datenfestplatte
LUKS (Linux Unified Key Setup) ist der Standard zur Festplattenverschlüsselung unter Linux. In diesem Artikel wird eine zweite Festplatte verschlüsselt eingebunden. Die Verschlüsselung erfolgt direkt auf der Partition – ohne LVM.
Szenario
- Zweite Festplatte:
/dev/sdb - Eine Partition:
/dev/sdb1(20 GB) - Mountpoint:
/mnt/data - Einhängen beim Systemstart mit Passwortabfrage
Voraussetzungen
- apt-get install cryptsetup cryptsetup-initramfs
Partition anlegen
Falls /dev/sdb noch keine Partition hat:
- fdisk /dev/sdb
Im fdisk-Dialog:
n → neue Partition
p → primär
1 → Nummer 1
→ Enter (Standard-Start)
→ Enter (Standard-Ende, gesamte Disk)
w → schreiben und beenden
Ergebnis prüfen:
- fdisk -l /dev/sdb
Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 41943039 41940992 20G 83 Linux
LUKS-Container erstellen
- cryptsetup luksFormat /dev/sdb1
WARNING! ======== This will overwrite data on /dev/sdb1 irrevocably. Are you sure? (Type uppercase yes): YES Enter passphrase for /dev/sdb1: Verify passphrase:
LUKS-Container öffnen
- cryptsetup open /dev/sdb1 cryptdata
Enter passphrase for /dev/sdb1:
Der Container ist jetzt unter /dev/mapper/cryptdata verfügbar.
Dateisystem erstellen
- mkfs.ext4 /dev/mapper/cryptdata
Mountpoint erstellen
- mkdir /mnt/data
Manuell einhängen (Test)
- mount /dev/mapper/cryptdata /mnt/data
- df -h /mnt/data
Filesystem Size Used Avail Use% Mounted on /dev/mapper/cryptdata 20G 2.1M 19G 1% /mnt/data
Zum Testen wieder aushängen:
- umount /mnt/data
- cryptsetup close cryptdata
Automatisch einhängen beim Systemstart
UUID ermitteln
- blkid /dev/sdb1
/dev/sdb1: UUID="eab7be99-90d8-4986-88a7-bdfb9d7ff502" TYPE="crypto_LUKS" PARTUUID="89a985e7-01"
/etc/crypttab
Trägt den LUKS-Container ein, damit er beim Booten geöffnet wird:
cryptdata UUID=eab7be99-90d8-4986-88a7-bdfb9d7ff502 none luks,initramfs
| Feld | Bedeutung |
|---|---|
cryptdata |
Name des Mappers unter /dev/mapper/
|
UUID=... |
UUID der verschlüsselten Partition |
none |
Passwort wird interaktiv beim Boot abgefragt |
luks |
Format-Typ |
initramfs |
Container wird bereits im initramfs geöffnet – stellt sicher, dass die Passwortabfrage beim Boot erscheint |
/etc/fstab
Hängt das Dateisystem nach dem Öffnen ein:
/dev/mapper/cryptdata /mnt/data ext4 defaults 0 2
Update Ramdisk
- update-initramfs -u
Systemstart
Please unlock disk cryptdata:
Beim nächsten Booten erscheint eine Passwortabfrage für /dev/sdb1.
Nach korrekter Eingabe wird /mnt/data automatisch eingehängt.
Ergebnis prüfen
- df -h /mnt/data
Filesystem Size Used Avail Use% Mounted on /dev/mapper/cryptdata 20G 2.1M 19G 1% /mnt/data
- cryptsetup status cryptdata
/dev/mapper/cryptdata is active and is in use. type: LUKS2 cipher: aes-xts-plain64 keysize: 512 bits key location: keyring device: /dev/sdb1
Nützliche Befehle
| Befehl | Bedeutung |
|---|---|
cryptsetup luksDump /dev/sdb1 |
LUKS-Header anzeigen (Slots, Algorithmen) |
cryptsetup luksAddKey /dev/sdb1 |
Weiteres Passwort hinzufügen (bis zu 8 Slots) |
cryptsetup luksChangeKey /dev/sdb1 |
Passwort ändern |
cryptsetup open /dev/sdb1 cryptdata |
Container manuell öffnen |
cryptsetup close cryptdata |
Container manuell schließen |