On Sun, Jun 14, 2026 at 04:21:33 +0200, Borden via wrote:
> I appreciate the thoughtful response. The problem I'm trying to solve is:
>
> $ sudo cryptsetup luksAddKey --key-file=<(gpg --decrypt "$EXISTING_KEY")
> --new-keyfile=<(gpg --decrypt "$NEW_KEYFILE") "$DEVICE"Â
> So far, it seems like this is theoretically possible, but it's failing (as
> you probably saw immediately) for reasons that I can only guess. I'm also
> learning that sudo throws another layer of complexity as it runs in a
> different user space that might not have access to the same unprivileged
> files.
Your syntax looks reasonable, so if it's failing, it's most likely
because cryptsetup wants to treat its --key-file and/or --new-keyfile
arguments as actual files (e.g. seeking back and forth within them),
instead of sequential access pipes.
I'm not familiar with cryptsetup. Looking at
<https://manpages.debian.org/trixie/cryptsetup-bin/cryptsetup-luksAddKey.8.en.html>
and
<https://manpages.debian.org/trixie/cryptsetup-bin/cryptsetup.8.en.html>
doesn't reveal the inner workings of these options, unfortunately.
It does say that you can use --keyfile=- to read from stdin, but that
won't work if you need to do it for two different passphrases
simultaneously.
If cryptsetup needs both --key-file AND --new-keyfile to be regular
files, and doesn't give a means of piping both of them in from separate
FDs, then you may be out of luck here. I can give some ideas, but
none of them will be perfect, and you may already have rejected some
or all of them.
Idea 1: Use temporary files in an in-memory file system. I don't know
the environment in which you're running this command, but if
the /run file system (or an equivalent) is available, you
can put temp files there, and they'll never touch a permanent
storage device. Make sure both you *and* root have access to
the temp files. There are parts of /run that root can't read.
You may end up needing to create your own subdirectory for them.
Idea 2: Use something like Expect to create a pseudoterminal in which
you can run crypsetup in "interactive" mode, and interact
with it programmatically to send the two passphrases via
Expect commands.
Idea 3: Patch cryptsetup to take --keyfile-fd=N and --new-keyfile-fd=M
arguments. Then use something like
cryptsetup luksAddKey --keyfile-fd=3 --new-keyfile-fd=4 "$dev" \
3< <(gpg --decrypt "$old") 4< <(gpg --decrypt "$new")
Copy whatever logic --keyfile=- is currently using to avoid
seeking within the input stream. Submit your patch to the
maintainers of cryptsetup so other people can benefit from it.
Idea 4: Do a web search for other people having this problem, and see
if they've come up with any other workarounds. You can't
possibly be the first person running into this issue.