Sblocco di partizioni criptate con una chiavetta USB in Debian
Jump to navigation
Jump to search
| Attenzione questo articolo è ancora incompleto. Sentiti libero di contribuire cliccando sul tasto edit. |
Introduzione
- Una volta avviata una installazione con delle partizioni cifrate, normalmente viene richiesta la password per sbloccare i volumi luks. È possibile sbloccare i volumi luks utilizzando un keyfile, che può essere nascosto in una chiavetta usb
- In pratica si abiliterà lo sblocco del volume con un keyfile
- Si scriverà il keyfile in un settore non utilizzato della chiavetta (creare una partizione più piccola, ed utilizzare lo spazio vuoto alla fine)
- Si abiliterà la creazione di iun dispositivo udev specifico all'inserimento
- Si imposterà lo script di sblocco automatico del volume leggendo il keyfile dalla chiavetta
- In caso non ci sia la chiavetta disponibile, verrà richiesta la password di sblocco
Impostazione sblocco con keyfile
Partizionamento chiavetta
sudo fdisk -l /dev/sde
Disk /dev/sde: 1.9 GiB, 2000683008 bytes, 3907584 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xb4a7ed93 Device Boot Start End Sectors Size Id Type /dev/sde1 2048 3907583 3905536 1.9G c W95 FAT32 (LBA)
Creazione device udev per chiavetta
sudoedit /etc/udev/rules.d/99-unlock-luks.rules
# ATTRS{serial}=$(udevadm info /dev/sde | grep ID_SERIAL_SHORT | cut -f 2 --delimiter='=')
SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{manufacturer}=="USB", ATTRS{product}=="DISK", ATTRS{serial}=="90B90800FFAF17EA", SYMLINK+="usbkey%n"
SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{manufacturer}=="USB", ATTRS{product}=="DISK", ATTRS{serial}=="90B90800FFAF17EA", SYMLINK+="usbkey%n"
sudo udevadm control --reload-rules
#!/bin/sh TRUE=0 FALSE=1 # flag tracking key-file availability OPENED=$FALSE # check and modprobe the USB driver if not already loaded cat /proc/modules | busybox grep usb_storage >/dev/null 2>&1 USBLOAD=0$? if [ $USBLOAD -gt 0 ]; then modprobe usb_storage >/dev/null 2>&1 fi # give the system time to settle and open the USB device sleep 10 # check for the specifc /dev/usbkey device created by udev using /etc/udev/rules.d/99-unlock-luks.rules if [ -b /dev/usbkey ]; then # if device exists then output the keyfile from the usb key (hidden key is 4096 bytes long starting at 3905550 bytes) #dd if=/dev/usbkey bs=512 skip=4 count=8 | cat dd if=/dev/usbkey bs=512 skip=3905550 count=8 | cat OPENED=$TRUE fi if [ $OPENED -ne $TRUE ]; then #echo "FAILED to get USB key file ..." >&2 /lib/cryptsetup/askpass "Try LUKS password: " else echo "Success loading key file. Moving on." >&2 fi sleep 2
Impostazione dello sblocco tramite script
sudoedit /etc/crypttab
md1_crypt UUID=645431c0-44c2-4b17-8b7f-d9007f2bf3f2 none luks,keyscript=/usr/local/sbin/unlockusbkey.sh
Riavvio e test
sudo update-initramfs -u -k all sudo reboot