如何在Windows上安装和使用gpg-agent?

时间:2018-05-14 14:32:57

标签: windows git gnupg gpg-agent

我试图开始签署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

3 个答案:

答案 0 :(得分:5)

我需要通知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 Entry”对话框!

enter image description here

我可能会遗漏一些自动启动gpg-agent或了解会话生命周期的内容,但我会回过头来了解更多详情。

答案 1 :(得分:2)

  1. 您可以使用gpgconf --launch gpg-agent使gpg-agent在Windows上在后台运行。

  2. 要使gpg-agent在登录时自动运行,我在Task Scheduler中添加了一个任务:

gpg-agent-autostart

  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 :(得分:1)

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

在安装 Gpg4win 时检查它(俄语安装程序)enter image description here

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

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

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

不幸的是,我还没有找到在会话(重新启动)之间保留密码的方法。

相关问题