【问题标题】:Avoiding problems with gpg-agent when running from scripts - gpg2从脚本运行时避免 gpg-agent 出现问题 - gpg2
【发布时间】:2019-03-07 17:46:18
【问题描述】:

我正在尝试使用 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 或我的脚本的其他实例的情况下安全地使用 shell 脚本中的 gpg

详情

阅读gpg docs我看到了:

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

    This is dummy option. gpg always requires the agent.

然后gpg-agent docs 说:

--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

【问题讨论】:

    标签: bash gnupg gpg-agent


    【解决方案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
    

    【讨论】:

    • 唉,gpg --homedir 相当于我设置了$GNUPGHOME。正如我所写:“我认为这很容易。将$GNUPGHOME 设置到临时目录并完成它”。但它仍然会使用例如/run/user/$(id -u)/gnupg 我还没有办法避免。
    猜你喜欢
    • 2018-04-26
    • 2020-03-20
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多