Skip to content

Instantly share code, notes, and snippets.

@sillyfellow
Created March 9, 2020 07:29
Show Gist options
  • Save sillyfellow/fb50fc5fbf37028bb9d6d702b789f683 to your computer and use it in GitHub Desktop.
Save sillyfellow/fb50fc5fbf37028bb9d6d702b789f683 to your computer and use it in GitHub Desktop.
dm-crypt with LUKS
------------------
LUKS with dm-crypt has better encryption and makes it possible to have multiple passphrase for the same partition or to change the password easily. To test if LUKS is available, simply type # cryptsetup --help, if nothing about LUKS shows up, use the instructions below Without LUKS. First create a partition if necessary: fdisk /dev/sdc.
Create encrypted partition
# dd if=/dev/urandom of=/dev/sda3 # Optional. For paranoids only (takes days)
# cryptsetup -y luksFormat /dev/sda3 # This destroys any data on sda3
# cryptsetup luksOpen /dev/sda3 sda3
# mkfs.ext3 /dev/mapper/sda3 # create ext3 file system
# mount -t ext3 /dev/mapper/sda3 /mnt
# umount /mnt
# cryptsetup luksClose sda3 # Detach the encrypted partition
Attach
# cryptsetup luksOpen /dev/sda3 sda3
# mount -t ext3 /dev/mapper/sda3 /mnt
Detach
# umount /mnt
# cryptsetup luksClose sda3
dm-crypt without LUKS
# cryptsetup -y create sda3 /dev/sda3 # or any other partition like /dev/loop0
# dmsetup ls # check it, will display: sda3 (254, 0)
# mkfs.ext3 /dev/mapper/sda3 # This is done only the first time!
# mount -t ext3 /dev/mapper/sda3 /mnt
# umount /mnt/
# cryptsetup remove sda3 # Detach the encrypted partition
Taken/inspired from
http://sleepyhead.de/howto/?href=cryptpart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment