Thursday 20 October 2011

Linux Encrypted Flash Drive - LUKS

So you pull your bunch of keys out of your pocket and feel for your flash disk, you don't feel it. You look frantically over your keyring and its gone. Were the contents or the partition encrypted?
Encrypt your Key in Linux
This has been tested in Ubuntu 11.10 and for the purposes of the demonstration the partition is /dev/sdb1 - please make sure this is the correct partition for your Flash key, DaF will NOT be held responsible for lost data!
Were using 256 bit Luksformat, which is a good standard, but make sure you use a pass phrase thats at least 12 characters long, that doesn't contain dictionary words but does contain characters, numbers and symbols.
First of all, make a backup of the contents of your key.
Then open your favorite terminal emulator and do the following:
 mac@pentest:~$ sudo umount /dev/sdb1
 mac@pentest:~$ sudo cryptsetup luksFormat /dev/sdb1
This will present you with the following:
WARNING!
========
This will overwrite data on /dev/sdb1 irrevocably.

Are you sure? (Type uppercase yes):
You should then answer (in UPPERCASE):
 YES
You'll be prompted for a pass phrase:
 Enter LUKS passphrase:
Verify your pass phrase
 Verify passphrase:
Next you'll need to open the encrypted wrapper to format the drive:
 mac@pentest:~$ sudo cryptsetup luksOpen /dev/sdb1 EncryptedFlashDisk
Now we need to format the drive and choose a drive label for it, in my case it will be EncryptedFlashDisk:
 mac@pentest:~$ sudo mkfs.vfat /dev/mapper/EncryptedFlashDisk
The output will look similar to this, you'll get some output like below, but don't worry:
mkfs.vfat 3.0.9 (31 Jan 2010)
unable to get drive geometry, using default 255/63
Thats it the next time you plug in the drive you'll be prompted for a passphrase:
encrypted_flash_disk_password_prompt
Encrypted Flash Disk Password Prompt