Gpg symmetric encryption using pipes

command lineencryptiongentoognupgpipe

I'm trying to generate keys to lock my drive (using DM-Crypt with LUKS) by pulling data from /dev/random and then encrypting that using GPG.

In the guide I'm using, it suggests using the following command:

dd if=/dev/random count=1 | gpg --symmetric -a >./[drive]_key.gpg

If you do it without a pipe, and feed it a file, it will pop up an (n?)curses prompt for you to type in a password. However when I pipe in the data, it repeats the following message four times and sits there frozen:

pinentry-curses: no LC_CTYPE known assuming UTF-8

It also says can't connect to '/root/.gnupg/S.gpg-agent': File or directory doesn't exist, however I am assuming that this doesn't have anything to do with it, since it shows up even when the input is from a file.

So I guess my question boils down to this: is there a way to force gpg to accept the passphrase from the command line, or in some other way get this to work, or will I have to write the data from /dev/random to a temporary file, and then encrypt that file? (Which as far as I know should be alright due to the fact that I'm doing this on the LiveCD and haven't yet created the swap, so there should be no way for it to be written to disk.)

Best Answer

Make sure you own the tty:

# ls -l $(tty)
crw--w----. 1 foo tty 136, 0 MarĀ  1 16:53 /dev/pts/0
# chown root $(tty)

Set GPG_TTY:

# export GPG_TTY=$(tty)

gpg/pinentry should work after these steps.

Related Question