Skip to content

/errors/gpg/signing-failed-inappropriate-ioctl

gpg: signing failed: Inappropriate ioctl for device

The commands on this page have not been executed by our verification runner yet.updated 2026-10-20
tool
GnuPG
exit code
2
versions
GnuPG 2.2, GnuPG 2.4
os
linux, macos

gpg prints gpg: signing failed: Inappropriate ioctl for device when it needs your key's passphrase but its pinentry program cannot open the terminal. The usual fix is to tell gpg-agent which terminal to use by setting GPG_TTY.

Fix: set GPG_TTY

bash
echo 'export GPG_TTY=$(tty)' >> ~/.bashrc   # or ~/.zshrc
export GPG_TTY=$(tty)
echo test | gpg --clearsign >/dev/null && echo "signing works"

The GnuPG manual asks for this line in the shell's startup file, because gpg-agent's terminal pinentry needs to know the current tty.

Fix: use a graphical pinentry

When gpg runs from an IDE or a GUI Git client, there is no terminal at all. Point gpg-agent at a graphical pinentry:

~/.gnupg/gpg-agent.conf
pinentry-program /usr/bin/pinentry-gnome3

On macOS, pinentry-mac (Homebrew) is the usual choice. Restart the agent after changing the file:

bash
gpgconf --kill gpg-agent

Signing Git commits

bash
git config --global user.signingkey <KEY-ID>
git config --global commit.gpgsign true
git commit -S -m "signed commit"

If git commit -S fails with this error, run echo test | gpg --clearsign in the same shell: if that fails too, the problem is gpg, not git.

FAQ

Why does git commit -S fail with this error?

git runs gpg to sign the commit; gpg needs to prompt for the key's passphrase and cannot find the terminal. Setting GPG_TTY in your shell profile fixes git too.

Sources