9

我正在尝试使用脚本gpg--clearsign的文件(用于 debian 打包目的)。

我有一个导出的无密码private-key.gpg文件,并且想要:

gpg --clearsign -o output input

我不想弄乱当前用户的~/.gnupg,或者/run/user/$(id -u)/gnupg因为他们与我的脚本无关。此外,脚本可以同时在多个实例中运行,我不希望它们相互干扰。

我以为这很容易。设置$GNUPGHOME到临时目录并完成它。但是我无法弄清楚如何gpg在不弄乱用户标准配置的情况下在脚本中运行。似乎gpg已经竭尽全力避免无法避免gpg-agentgpg-agent坚持使用全局/硬编码路径。

我可以把所有东西都放在下面$GNUPGHOME吗?或者我如何在gpg不影响用户配置或使用gpg我的脚本或其他实例的情况下安全地使用 shell 脚本?

细节

阅读gpg 文档我看到:

--use-agent
--no-use-agent

    This is dummy option. gpg always requires the agent.

gpg-agent 文档说:

--use-standard-socket
--no-use-standard-socket
--use-standard-socket-p

    Since GnuPG 2.1 the standard socket is always used.
    These options have no more effect. The command gpg-agent
    --use-standard-socket-p will thus always return success.

这个“标准套接字”大概在/run/user/$(id -u)/gnupg- 所以看来我无法避免 gpg 弄乱用户对 gpg 的“正常”使用。

版本:Debian 9/stretch/stable 上的 gpg 2.1.18

4

1 回答 1

1

如果您无法阻止 gpg 创建文件,那么给 gpg 一个放置它们的位置是否对当前进程来说是独一无二的会有帮助吗?

# Create a temporary directory for gpg.
dir="$(mktemp -d)"

# Remove the directory and its contents when the script exits.
trap '[[ ! -d "${dir}" ]] || rm -r "${dir}"' EXIT

# Put your private-key.gpg in the temporary directory.
$(your command here)

# Tell gpg to use the temporary directory.
gpg --homedir "${dir}" --clearsign -o output input
于 2019-12-21T18:21:32.603 回答