Ssh – Gentoo Linux GPG encrypts properly a file passed through parameter but throws “Inappropriate ioctl for device” when reading from standard input

gentoogpggpg-agentssh

I am running Gentoo Hardened with kernel 4.1.7-hardened-r1 and I am trying to encrypt a file using GPG from a shell session opened from SSH and with the DISPLAY variable disabled in order to use pinentry-curses for password prompt. Using gpg -o file.gpg --symmetric file I can encrypt just fine. Using pv file | gpg -o file.gpg --symmetric I get the following error message:

gpg-agent[30745]: command get_passphrase failed: Inappropriate ioctl for device

Best Answer

You should set yout GPG_TTY variable for it to work, as in this document:

GPG_TTY=$(tty)
export GPG_TTY

Those two lines are supposed to be in your .bashrc (assuming bash), so they're run every time you open new terminal session.

There's another solution, though: in bash you can run your pv and pretend it's a file, using process substitution:

gpg -o file.gpg --symmetric <(pv file)

As such, it might not be a good idea to pipe-in things to programs that expect additional input. It can work differently than expected.

Related Question