"gpg: signing failed: Inappropriate ioctl for device" 在 MacOS 上使用 Maven

"gpg: signing failed: Inappropriate ioctl for device" on MacOS with Maven

我已经使用 brew install gpg 通过 Homebrew 安装了 GPG。 它安装在 2.2.17.

版本中

在我的 Maven POM 中我有这个片段:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-gpg-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>sign-artifacts</id>
            <phase>verify</phase>
            <goals>
                <goal>sign</goal>
            </goals>
        </execution>
    </executions>
</plugin>

但是当 运行 mvn clean verify 我得到这个错误:

gpg: Beglaubigung fehlgeschlagen: Inappropriate ioctl for device
gpg: signing failed: Inappropriate ioctl for device

我该如何解决这个错误?

我已经添加了

GPG_TTY=$(tty)
export GPG_TTY

到我的 ~/.bash_profile 文件。现在可以使用了。

另见 https://github.com/Homebrew/homebrew-core/issues/14737#issuecomment-309848851

对我来说,发生这种情况是因为终端 window 不够大,无法容纳密码短语 TUI。打开一个更大的终端选项卡然后重新运行 gpg 命令后,我能够看到密码终端用户界面。

在 macOS 上,您可能希望使用 pinentry-mac 让 GUI window 输入密码并可选择将密码存储在钥匙串中。

您可以通过 Homebrew 安装它:

brew install pinentry-mac

并在您的 ~/.gnupg/gpg-agent.conf 配置中使用以下行启用它(如果不存在则创建它):

pinentry-program /usr/local/bin/pinentry-mac

试试这个

gpg --use-agent --armor --detach-sign --output $(mktemp) pom.xml

如果有人在 bash 中键入 gpg 命令时收到此错误消息,请尝试添加 --no-tty。这为我修好了。