我决定再次查看一下,并了解其工作原理。GPG使用术语“缓存”来存储密码。最长存储时间可能受到两个限制:
- 自从最初添加密钥以来,保持密码短语的时间。
- 自上次访问以来保留密码短语的时间。
此外,两个约束都存在两种变体,一种是GPG密钥,另一种是SSH密钥(如果启用了支持)。
来自gpg-agent(1)
以下内容的相关手册页条目:
--default-cache-ttl n
Set the time a cache entry is valid to n seconds. The default
is 600 seconds.
--default-cache-ttl-ssh n
Set the time a cache entry used for SSH keys is valid to n sec‐
onds. The default is 1800 seconds.
--max-cache-ttl n
Set the maximum time a cache entry is valid to n seconds. After
this time a cache entry will be expired even if it has been
accessed recently. The default is 2 hours (7200 seconds).
--max-cache-ttl-ssh n
Set the maximum time a cache entry used for SSH keys is valid to
n seconds. After this time a cache entry will be expired even
if it has been accessed recently. The default is 2 hours (7200
seconds).
密码总是缓存的(在内存中,不在磁盘上!已通过git repo验证$HOME
),因此不需要ssh-add
。例如,对伪数据进行签名已经触发了缓存:
$ echo | gpg -s >/dev/null
(passphrase requested
$ echo | gpg -s >/dev/null
(signing proceeds without asking for passphrase)
要永久更改gpg-agent的缓存设置,请编辑〜/ .gnupg / gpg-agent.conf`并添加以下内容:
default-cache-ttl 60 # Expire GPG keys when unused for 1 minute
max-cache-ttl 600 # Expire GPG keys after 10 minutes since addition
我试图通过指定启用SSH代理支持enable-ssh-support
,但这使gpg-agent要求您提供另一个密钥来加密该密钥,然后将您的私钥存储在中~/.gnupg/private-keys.d/
。不适合我,我将坚持使用双重ssh-agent / gpg-agent方法。
一些奖励提示:
max-cache-ttl-ssh
可以在添加密钥时指定SSH代理的等效项,例如:ssh-add -t 600 ~/.ssh/id_rsa
为防止将GPG密码存储在代理中,请禁用该代理。在较新的GPG版本中,该选项将--no-use-agent
被忽略,但是您可以通过清除相关的环境变量来防止使用代理。这样做的一些方法:
echo | GPG_AGENT_INFO= gpg -s # temporary
export GPG_AGENT_INFO=; echo | gpg -s # until the current shell is closed
gpg-connect-agent
吗?