From: https://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions

CLONING/IMAGING: If you clone or image a LUKS container, you make a copy 
of the LUKS header and the master key will stay the same! That means that if 
you distribute an image to several machines, the same master key will be used 
on all of them, regardless of whether you change the passphrases. Do NOT do this! 
If you do, a root-user on any of the machines with a mapped (decrypted) container 
or a passphrase on that machine can decrypt all other copies, breaking security. 
See also Item 6.15. 

So: I have a notebook "A" (a Linux Desktop installed with LUKS & and I have root access to it) and I clone the whole disk of it to notebook "B", and the notebook "B" had it's LUKS password changed.

My question: How can I mount/decrypt notebook "B" LUKS partition with ONLY the known master key from "A"?* (and I know the cipher type too)

*UPDATE: What are the exact commands to mount the B's HDD on A?

  • See also luksHeaderBackup / luksHeaderRestore Mar 15, 2014 at 17:48

3 Answers 3


Opening a LUKS volume leads to the creation of a new device mapper object. Let's assume the original (LVM) volume is storage-crypto (from a DM perspective) and the decrypted volume is called crypto. You get the device mapper configuration by this:

dmsetup table --showkeys crypto
0 104853504 crypt aes-cbc-essiv:sha256 b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c 0 253:5 4096

The key part is exactly what you get from

cryptsetup luksDump --dump-master-key /dev/storage/crypto

I.e. if you know the cipher and the key then you can set up such a DM volume yourself.

See the kernel documentation about this device mapper target (dm-crypt).

In order to decrypt a LUKS volume you have to determine the size of the volume in 512-byte blocks:

blockdev --getsz /dev/sda1

With this value you can create a new DM volume. This should work:

echo "0 104857600 crypt aes-cbc-essiv:sha256 "\
"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c "\
"0 /dev/sda1 4096" | dmsetup create luks_volume
  • dmsetup would work fine, or you could replace the LUKS header and cryptsetup luksOpen Mar 15, 2014 at 17:41
  • Can you please describe the opening part in more detail? Thanks! ex.: I have the notebook "B"'s HDD in an USB rack, plugged in tho notebook "A". Mar 16, 2014 at 9:26
  • @evachristine What exactly do you want explained? Mar 16, 2014 at 13:50
  • sorry, updated the original questions. Thanks. Mar 16, 2014 at 20:55
  • @evachristine I added some info to the answer. Mar 16, 2014 at 22:31

Provided you have the master key and are root

cryptsetup --master-key-file pathToMasterKey luksOpen /dev/sdX bHDD
mount /dev/mapper/bHDD /mnt/bHDD

If you need to obtain the master key have A drive decrypted and run the following as root

dmsetup table --showkeys

copy the key and put it into a text file then run

xxd -r -p masterKey.txt masterKey.bin

you would use masterKey.bin in your cryptsetup command as the master key file


First off, you should only use the masterkey if you don't know the passphrase anymore. Because if someone knows your passphrase you can change it, but if someone knows your masterkey you have to reformat the whole disk/partition and restore your backup to change it. So only use the masterkey to add a new passphrase.

Assuming the header is intact and you already have the masterkey this are the steps to add a new passphrase:

1. Backup the LUKS header in case something goes wrong

cryptsetup luksHeaderBackup --header-backup-file <file> <device>

2. Create a file with the masterkey in binary form

When you backup the masterkey you will get an output like this:

0 200704 crypt aes-cbc-essiv:sha256
0 7:0 4096

The long hex string is the masterkey, to create the binary file use this command:

Warning: Before you execute the command, make sure the file is stored on an encrypted place, and delete it after the procdure!

echo "masterkey" | xxd -r -p > <master-key-file>

3. Add a new passphrase

cryptsetup luksAddKey --master-key-file=<master-key-file> <luks device>

Now you can mount LUKS from the command line or use a GUI tool like a file explorer or the gnome-disk-utility.

In case this didn't solve the problem you should have a look on the Backup and Data Recovery section of the cryptsetup wiki.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.