CRYPTSETUP-LUKSCHANGEKEY(8)

πŸ’– CRYPTSETUP-LUKSCHANGEKEY πŸ’–

okay bestie, we're deep in the cryptsetup section of the maintenance commands, and this one is literally about swapping out a passphrase you already have for a shiny new one. buckle up πŸŽ€


✨ NAME ✨

cryptsetup-luksChangeKey β€” change an existing passphrase πŸ”‘βž‘οΈπŸ”‘


🌸 SYNOPSIS 🌸

cryptsetup luksChangeKey [<options>] <device> [<new key file>]

πŸ¦‹ DESCRIPTION πŸ¦‹

So the whole vibe here is: you have a passphrase, and you want it to be a different passphrase. That's it, that's the job. πŸ’…

The passphrase you're changing has to come from somewhere β€” either you type it in interactively, or you hand it over with --key-file. The new passphrase can also be typed in interactively, or it can live in a file, and you pass that file as the positional argument. slay, options on options ✨

Now here's the tea on keyslots πŸ«– β€” if you specify a keyslot (that's via --key-slot), then you must give the passphrase for that keyslot, and the new passphrase will overwrite that specified keyslot. simple.

But if you don't specify a keyslot? Then the behavior depends on whether there's still a free keyslot lying around:

  • if there is a free keyslot, the new passphrase goes into that free keyslot first, and only then does the keyslot holding the old passphrase get purged. very demure, very mindful 🌸
  • if there is no free keyslot, then the keyslot with the old passphrase just gets overwritten directly. spicy. 🌢️
WARNING: if a keyslot is overwritten, a media failure during this operation can cause the overwrite to fail after the old passphrase has been wiped, which makes the LUKS container inaccessible. like, gone gone. 😭 LUKS2 mitigates that by never overwriting the existing keyslot area as long as there's free space in the keyslots area for at least one more LUKS2 keyslot. so LUKS2 is the friend who checks on you 🫢

Also, if you need to use both luksChangeKey and reencrypt (say, because you're recovering from a key leak πŸ’€), you have to use them in that order β€” otherwise you leak the new volume key. no cap, order matters.

Some parameters only actually do anything if you're on the LUKS2 format, since LUKS2 supports per-keyslot parameters. For LUKS1, the PBKDF type and hash algorithm are always the same for all keyslots. that's just how LUKS1 is, it doesn't do variety πŸŽ€

And <options> can be any of these cuties:

--key-file, --keyfile-offset, --keyfile-size,
--new-keyfile-offset, --iter-time, --pbkdf, --pbkdf-force-iterations,
--pbkdf-memory, --pbkdf-parallel, --new-keyfile-size, --key-slot,
--force-password, --hash, --header, --disable-locks, --type,
--keyslot-cipher, --keyslot-key-size, --timeout, --verify-passphrase

more coming, bestie, don't go anywhere πŸ’œ

✨ OPTIONS ✨

okay bestie, this is the big one, the options buffet, the whole menu πŸ’… every single flag, no skips, let's go

  • --batch-mode, -q β€” kills every single confirmation question. use with care, fr fr! 🫢 and if you didn't also pass --verify-passphrase, this one also turns off the passphrase verification. so like, no double-checking, no take-backs.
  • --debug or --debug-json β€” run in debug mode with the full diagnostic logs. debug output lines always get prefixed with #. and if you go with --debug-json, you also get extra LUKS2 JSON data structures printed out. fancy 🌸
  • --disable-locks β€” disables lock protection for metadata on disk. this one is only valid for LUKS2 and gets ignored for other formats, iykyk.
WARNING: do not use this option unless you're running cryptsetup in a restricted environment where locking is literally impossible to do (like, where the /run directory can't be used). seriously. no cap. πŸ’€
  • --force-password β€” don't run password quality checking on new LUKS passwords. this option is ignored if cryptsetup was built without password quality checking support. for more info about password quality check, peep the manual pages for pwquality.conf(5) and passwdqc.conf(5).
  • --hash, -h <hash-spec> β€” the hash you specify here is what gets used for PBKDF2 and the AF splitter.
  • --header <device or file storing the LUKS header> β€” use a detached (separated) metadata device or file where the LUKS header lives. this option lets you store the ciphertext and the LUKS header on different devices, which is very main character of them. πŸŽ€ for commands that change the LUKS header (like, say, luksAddKey), you specify the device or file with the LUKS header directly as the LUKS device.
  • --help, -? β€” show the help text and the default parameters.
  • --iter-time, -i <number of milliseconds> β€” how many milliseconds to spend doing PBKDF passphrase processing. if you pass 0 as the parameter, it selects the compiled-in default.
  • --key-file, -d file β€” read the passphrase from the file. if the name you give is -, then the passphrase gets read from stdin, and in that case reading will not stop at newline characters. the passphrase supplied via --key-file is always the passphrase for the existing keyslot requested by the command. if you want to set a new passphrase via a key file, you have to use a positional argument instead. see the section NOTES ON PASSPHRASE PROCESSING in cryptsetup(8) for more info. πŸ¦‹
  • --keyfile-offset value β€” skip value bytes at the beginning of the key file.
  • --keyfile-size, -l value β€” read a maximum of value bytes from the key file. the default is to read the whole file up to the compiled-in maximum, which you can query with --help. supplying more data than the compiled-in maximum aborts the operation, periodt. this option is super useful for cutting trailing newlines, for example. and if --keyfile-offset is also given, the size count starts after the offset.
  • --key-slot, -S <0-N> β€” for LUKS operations that add key material, this option lets you specify which keyslot gets selected for the new key. the maximum number of keyslots depends on the LUKS version: LUKS1 can have up to 8 keyslots, and LUKS2 can have up to 32 keyslots based on the keyslot area size and key size β€” but a valid keyslot ID can always be between 0 and 31 for LUKS2.
  • --keyslot-cipher <cipher-spec> β€” use this to set a specific cipher encryption for the LUKS2 keyslot area.
  • --keyslot-key-size <bits> β€” use this to set a specific key size for the LUKS2 keyslot area.
  • --new-keyfile-offset value β€” skip value bytes at the start when you're adding a new passphrase from the key file.
  • --new-keyfile-size value β€” read a maximum of value bytes when adding a new passphrase from the key file. the default is to read the whole file up to the compiled-in maximum length, which you can query with --help. supplying more than the compiled-in maximum aborts the operation. and when --new-keyfile-offset is also given, reading starts after the offset.
  • --pbkdf <PBKDF spec> β€” set the Password-Based Key Derivation Function (PBKDF) algorithm for the LUKS keyslot. the PBKDF can be: pbkdf2 (for PBKDF2 according to RFC2898), argon2i for Argon2i, or argon2id for Argon2id (see Argon2 at https://www.cryptolux.org/index.php/Argon2 for more info). for LUKS1, only PBKDF2 is accepted (no need to use this option at all). the default PBKDF for LUKS2 is set during compilation time and is available in the cryptsetup --help output. a PBKDF is used to increase the dictionary and brute-force attack cost for keyslot passwords, and the parameters can be time, memory and parallel cost. for PBKDF2, only the time cost (number of iterations) applies. for Argon2i/id, there's also memory cost (memory required during the process of key derivation) and parallel cost (number of threads that run in parallel during the key derivation).

note that increasing memory cost also increases time, so the final parameter values are measured by a benchmark. the benchmark tries to find iteration time (--iter-time) with the required memory cost --pbkdf-memory. if that's not possible, the memory cost gets decreased as well. the parallel cost --pbkdf-parallel is constant and is checked against the available CPU cores. you can see all PBKDF parameters for a particular LUKS2 keyslot with the cryptsetup-luksDump(8) command. πŸ‘‘

if you do not want to use the benchmark and want to specify all parameters directly, use --pbkdf-force-iterations with --pbkdf-memory and --pbkdf-parallel. this overrides the values without benchmarking. note it can cause extremely long unlocking time or cause out-of-memory conditions with unconditional process termination. use only in specific cases β€” for example, if you know the formatted device will be used on some small embedded system.

MINIMAL AND MAXIMAL PBKDF COSTS: for PBKDF2, the minimum iteration count is 1000 and the maximum is 4294967295 (maximum for a 32-bit unsigned integer). memory and parallel costs are not supported for PBKDF2. for Argon2i and Argon2id, the minimum iteration count (CPU cost) is 4, and the maximum is 4294967295 (maximum for a 32-bit unsigned integer). minimum memory cost is 32 KiB and maximum is 4 GiB. if the memory cost parameter is benchmarked (not specified by a parameter), it is always in the range from 64 MiB to 1 GiB. memory cost above 1GiB (up to the 4GiB maximum) can be set up only by the --pbkdf-memory parameter. the parallel cost minimum is 1 and maximum 4 (if enough CPU cores are available, otherwise it's decreased by the available CPU cores).

WARNING: increasing PBKDF computational costs above the mentioned limits gives you negligible additional security improvement. while elevated costs significantly increase brute-force overhead, they offer negligible protection against dictionary attacks β€” the marginal cost increase for processing an entire dictionary remains fundamentally insufficient. 😭
the hardcoded PBKDF limits represent engineered trade-offs between cryptographic security and operational usability. LUKS maintains portability and must be usable within a reasonable time on resource-constrained systems.
cryptsetup deliberately restricts the maximum memory cost (4 GiB) and parallel cost (4) parameters due to architectural limitations (like embedded and legacy systems).
PBKDF memory cost mandates actual physical RAM allocation with intensive write operations that must stay in physical RAM. any swap usage results in unacceptable performance degradation. memory management often overcommits allocations beyond available physical memory, expecting most allocated memory to stay unused. in such situations, since PBKDF always uses all allocated memory, it frequently causes out-of-memory failures that abort cryptsetup operations. πŸ’€
  • --pbkdf-force-iterations number β€” avoid the PBKDF benchmark and set the time cost (iterations) directly. it can only be used for a LUKS/LUKS2 device. see the --pbkdf option for more info.
  • --pbkdf-memory number β€” set the memory cost for PBKDF (for Argon2i/id, the number represents kilobytes). note that it's the maximal value; the PBKDF benchmark or the available physical memory can decrease it. this option is not available for PBKDF2.
  • --pbkdf-parallel number β€” set the parallel cost for PBKDF (number of threads, up to 4). note that it's the maximal value; it gets decreased automatically if the CPU online count is lower. this option is not available for PBKDF2.
  • --timeout, -t seconds β€” how many seconds to wait before timing out on passphrase input via terminal. it's relevant every single time a passphrase is asked. it has no effect if used together with --key-file. this option is useful when the system shouldn't stall if the user doesn't input a passphrase, like during boot. the default is a value of 0 seconds, which means wait forever. 🧚
  • --type type β€” specifies the required device type. for more info, read the BASIC ACTIONS section in cryptsetup(8).
  • --usage β€” show the short option help.
  • --verify-passphrase, -y β€” when interactively asking for a passphrase, ask for it twice and complain if both inputs don't match. ignored on input from file or stdin.
  • --version, -V β€” show the program version. πŸ’–

πŸ› REPORTING BUGS πŸ›

found a bug? bestie, report it at the cryptsetup mailing list <cryptsetup@lists.linux.dev> or in the Issues project section at https://gitlab.com/cryptsetup/cryptsetup/-/issues/new 🫢

please attach the output of the failed command with the --debug option added. that's the whole vibe check, thank you πŸ’…


πŸ‘€ SEE ALSO πŸ‘€


🌈 CRYPTSETUP 🌈

part of the cryptsetup project <https://gitlab.com/cryptsetup/cryptsetup/>. iconic behavior honestly ⭐


and that's the whole page bestie!! this was cryptsetup 2.8.8, dated 2026-09-07, from the CRYPTSETUP-LUKSCHANGEKEY(8) manual β€” go forth and change those keys, you absolute legend πŸ‘‘πŸ’–

πŸ“¦ where this page comes from