gpg-agent forwarding: inappropriate ioctl for device
When running gpg from a script, the --batch argument must be provided.
It happens when GPG is confused where to read input from. Simply configuring it to look for input from tty (the terminal connected to standard input) fixes it:
export GPG_TTY=$(tty)
This method does not work when you are inside an LXC container. Instead, add this to ~/.gnupg/gpg.conf
:
use-agent
pinentry-mode loopback
Then add this to ~/.gnupg/gpg-agent.conf
allow-loopback-pinentry
Then restart the agent with echo RELOADAGENT | gpg-connect-agent
.
(source)