【问题标题】:How do I install and use gpg-agent on Windows?如何在 Windows 上安装和使用 gpg-agent?
【发布时间】:2018-05-14 14:32:56
【问题描述】:

我正在尝试开始签署 Git 提交。我使用 keybase.io 设置了 GPG 密钥,并将其同步到我的本地计算机和 Git 服务器上。现在,我正在尝试解决在每次提交时输入密钥密码的问题。

PS> git commit -m "testing" --allow-empty

You need a passphrase to unlock the secret key for
user: "keybase.io/anthonymastrean <anthonymastrean@keybase.io>"
2048-bit RSA key, ID AD9184C0, created 2015-04-14 (main key ID 293FEB8B)

Enter passphrase:

据我了解,我需要安装 gpg-agent 之类的东西。我在 Windows 10 Pro 1803 上,所以我在看Gpg4win(由 GitHub 和其他人推荐)。我是通过Chocolatey安装的,所以我有完整的默认安装。

但是,我不知道如何让 gpg-agent 开始缓存我的密码。每次提交时都会提示我。

gpg-agent 说它正在运行

PS> gpg-agent
gpg-agent[4644]: gpg-agent running and available

我有这个 gpg-connect-agent 的东西,但我不知道如何处理它。

PS> gpg-connect-agent.exe
> help
# NOP
# CANCEL
# OPTION
# BYE
# AUTH
# RESET
# END
# HELP
# GETEVENTCOUNTER
# ISTRUSTED <hexstring_with_fingerprint>
# HAVEKEY <hexstrings_with_keygrips>
# KEYINFO [--[ssh-]list] [--data] [--ssh-fpr] [--with-ssh] <keygrip>
# SIGKEY <hexstring_with_keygrip>
# SETKEY
# SETKEYDESC plus_percent_escaped_string
# SETHASH (--hash=<name>)|(<algonumber>) <hexstring>
# PKSIGN [<options>] [<cache_nonce>]
# PKDECRYPT [<options>]
# GENKEY [--no-protection] [--preset] [--inq-passwd]
# READKEY <hexstring_with_keygrip>
# GET_PASSPHRASE [--data] [--check] [--no-ask] [--repeat[=N]]
# PRESET_PASSPHRASE [--inquire] <string_or_keygrip> <timeout> [<hexstring>]
# CLEAR_PASSPHRASE [--mode=normal] <cache_id>
# GET_CONFIRMATION <description>
# LISTTRUSTED
# MARKTRUSTED <hexstring_with_fingerprint> <flag> <display_name>
# LEARN [--send] [--sendinfo] [--force]
# PASSWD [--cache-nonce=<c>] [--passwd-nonce=<s>] [--preset]
# INPUT
# OUTPUT
# SCD <commands to pass to the scdaemon>
# KEYWRAP_KEY [--clear] <mode>
# IMPORT_KEY [--unattended] [--force] [<cache_nonce>]
# EXPORT_KEY [--cache-nonce=<nonce>] [--openpgp] <hexstring_with_keygrip>
# DELETE_KEY [--force|--stub-only] <hexstring_with_keygrip>
# GETVAL <key>
# PUTVAL <key> [<percent_escaped_value>]
# UPDATESTARTUPTTY
# KILLAGENT
# RELOADAGENT
# GETINFO <what>
# KEYTOCARD [--force] <hexstring_with_keygrip> <serialno> <id> <timestamp>
OK

我看到手册页讨论了如何在 Bash 会话中启动 gpg-agent,但我不确定如何将其转换为 Windows 并使其在 cmd.exe 和 PowerShell 中工作。

https://linux.die.net/man/1/gpg-agent

【问题讨论】:

  • 是的,这是关于生成密钥和设置签名,而不是在 Windows 上配置 gpg-agent 以缓存密码!
  • 哦,你是对的。我记得那篇文章里有。我将尝试挖掘包含该内容的文章。

标签: windows git gnupg gpg-agent


【解决方案1】:
  1. 您可以使用gpgconf --launch gpg-agent 使 gpg-agent 在 Windows 后台运行。

  2. 为了让 gpg-agent 在我登录时自动运行,我在任务计划程序中添加了一个任务:

  1. 要扩展密码的有效期,请将这些行添加到 gpg-agent.conf:

    default-cache-ttl 34560000
    
    max-cache-ttl 34560000
    

我尝试将号码设置为 999999999,但它根本不起作用

您可以使用以下命令找到 gpg-agent.conf 的位置:

$ gpgconf.exe --list-dirs

sysconfdir:C%3a\ProgramData\GNU\etc\gnupg
bindir:C%3a\Program Files (x86)\GnuPG\bin
libexecdir:C%3a\Program Files (x86)\GnuPG\bin
libdir:C%3a\Program Files (x86)\GnuPG\lib\gnupg
datadir:C%3a\Program Files (x86)\GnuPG\share\gnupg
localedir:C%3a\Program Files (x86)\GnuPG\share\locale
socketdir:C%3a\Users\Jerry\AppData\Roaming\gnupg
dirmngr-socket:C%3a\Users\Jerry\AppData\Roaming\gnupg\S.dirmngr
agent-ssh-socket:C%3a\Users\Jerry\AppData\Roaming\gnupg\S.gpg-agent.ssh
agent-extra-socket:C%3a\Users\Jerry\AppData\Roaming\gnupg\S.gpg-agent.extra
agent-browser-socket:C%3a\Users\Jerry\AppData\Roaming\gnupg\S.gpg-agent.browser
agent-socket:C%3a\Users\Jerry\AppData\Roaming\gnupg\S.gpg-agent
homedir:C%3a\Users\Jerry\AppData\Roaming\gnupg

gpg-agent.conf 在 homedir 中

【讨论】:

    【解决方案2】:

    我需要通知git 我已安装的 gpg 程序,它本身知道它应该使用的 gpg-agent。

    PS> git config --global gpg.program $(Resolve-Path (Get-Command gpg | Select-Object -Expand Source) | Select-Object -Expand Path)
    

    设置此配置后,弹出Gpg4win的“PIN输入”对话框!

    在自动启动 gpg-agent 或了解会话生命周期方面,我可能会遗漏一些东西,但我会回来提供更多详细信息。

    【讨论】:

    • 我是唯一一个最不明白这个答案的人吗?问题是从 Windows 机器连接到 Linux 遥控器。哪个 git 程序给出了 gpg 安装的上述路径?远程还是本地盒子?何时以及如何调用本地 git 可执行文件?远程 gpg 可执行文件不需要连接到本地密钥环吗?
    • @Meteorhead,我认为,问题是“Windows 上的 gpg-agent 仅将密码短语缓存 10 分钟”,而 Anthony 希望强制它在更长的时间内记住 GPG 密钥的密码短语,并且理想情况下是永远,以避免每次提交都输入密码。真的很烦(我今天遇到了这个问题=)
    【解决方案3】:

    除了陶珠的回答,
    您可以在 Gpg4win 附带的 GUI 密钥管理器 Kleopatra 中指定密码短语 (PIN) 的有效期而无需配置文件:

    在安装 Gpg4win 时检查它(俄语安装程序)

    在开始菜单中找到它并运行。
    转到菜单:设置 - 配置 Kleopatra...

    切换到 GnuPG System 标签,然后切换到 Private Keys 标签
    Expire cached PINs after N secondsSet maximum PIN cache lifetime to N seconds 两个设置的默认值更改为您的,我设置了这个:

    大值可让您避免在一天中每次 git 提交时频繁且烦人地输入 GPG 密钥的密码(直到下次 Windows 重新启动或指定时间到期)

    很遗憾,我还没有找到一种方法来保存会话(重启)之间的密码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 2010-11-04
      • 1970-01-01
      • 2016-07-14
      相关资源
      最近更新 更多