“gpg: signing failed: Inappropriate ioctl for device”

I was doing a release for a WooCommerce extension using our internal release tool. In the middle of the release process, I noticed there is an error that says “gpg: signing failed: Inappropriate ioctl for device” in the terminal. (Unfortunately I have closed the terminal and I don’t have the full error message anymore.)

It seems that suddenly my machine can’t make a verified git commit using my gpg signing key. I don’t know why. Maybe it’s due to the recent Mac OS update. Maybe it’s due to me restarting my machine. Maybe because I recently ran brew update and / or brew upgrade. 🤷‍♂️

Below is how I fixed the problem. I’m documenting this in case it help someone else, and for my future self.

The solution

I googled the error message and I found this GitHub issue: gpg: signing failed: Inappropriate ioctl for device.

It points to this Stack Exchange answer, which suggests to set  GPG_TTY environment variable.

I run printenv in the terminal and I noticed that I do not have that environment variable.

Since I use Oh My Zsh, I added the following into my ~/.zshrc file:

# For GPG to sign git commits. 
# See https://unix.stackexchange.com/a/257065/261332.
GPG_TTY=$(tty)
export GPG_TTY

GPG_TTY then shows up in the printenv command output.

However, that still does not work. I still could not create a new git commit for any git repo.

Since I suspect it may be due to recent Mac OS update, I googled “unable to sign git commit after mac update”, and I found this Stack Overflow answer which mentions pinentry. I saw the term pinentry in the full error message in the terminal earlier.

So I followed the instruction in the answer and did the following in the terminal:

  1. brew install pinentry-mac
  2. gpg --version – I already have version 2, so I’m good here.
  3. echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
    • This adds pinentry-program /opt/homebrew/bin/pinentry-mac into the gpg-agent.conf file.
  4. gpgconf --kill gpg-agent

Then, I tried to create a new git commit. A credential prompt window asked me to key in my password. It works! 🎉

Comments

Leave a Reply

Discover more from Gan Eng Chin

Subscribe now to keep reading and get access to the full archive.

Continue reading