我有一些使用 GnuPG 加密的东西gpg -e
。当我解密它们时,系统不会要求输入密码,它会立即解密。
它是否将密钥存储在某个地方并使用它(我也将我的密钥存储在 GnuPG 密钥链中,它是否使用它)?
如何强制系统每次都询问密码?
我有一些使用 GnuPG 加密的东西gpg -e
。当我解密它们时,系统不会要求输入密码,它会立即解密。
它是否将密钥存储在某个地方并使用它(我也将我的密钥存储在 GnuPG 密钥链中,它是否使用它)?
如何强制系统每次都询问密码?
它是否将密钥存储在某个地方并使用它(我也将我的密钥存储在 GnuPG 密钥链中,它是否使用它)?
GnuPG 只使用你的钥匙链中的钥匙,所以它必须在那里才能使用它。
如何强制系统每次都询问密码?
旧版本的 GnuPG 使用gpg-agent
,它将密码短语缓存给定时间。使用该选项--no-use-agent
或添加一行no-use-agent
以~/.gnupg/gpg.conf
防止使用代理。
~/.gnupg/gpg-agent.conf
对于较新的版本 (v2.1+),通过创建并添加以下行来禁用代理的密码缓存:
default-cache-ttl 1
max-cache-ttl 1
使用以下命令重新启动代理:
echo RELOADAGENT | gpg-connect-agent
GnuPG 2.2.15
--symmetric -c Encrypt with a symmetric cipher using a passphrase. The default sym- metric cipher used is AES-128, but may be chosen with the --cipher-algo option. This command may be combined with --sign (for a signed and sym- metrically encrypted message), --encrypt (for a message that may be decrypted via a secret key or a passphrase), or --sign and --encrypt together (for a signed message that may be decrypted via a secret key or a passphrase). gpg caches the passphrase used for symmetric encryption so that a decrypt operation may not require that the user needs to enter the passphrase. The option --no-symkey-cache can be used to disable this feature.
# encrypt files
gpg -c --no-symkey-cache file.txt
# decrypt files
gpg --no-symkey-cache file.txt.gpg
使用 --no-symkey-cache 选项,它不会缓存您的密码
加密“测试”文件应该给我们 test.gpg
# gpg -c test
但是不,我们得到了一些错误。
gpg: problem with the agent: Permission denied
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of 'test' failed: Operation cancelled
环回模式来救援!
# gpg -c --pinentry-mode=loopback test
它会提示您输入密码并按预期工作。
到了解密的时候,可能你换了用户就报错了:
gpg: problem with the agent: Permission denied
环回模式来救援!
# gpg --pinentry-mode=loopback test.gpg
经测试...
gpg (GnuPG) 2.2.20
libgcrypt 1.8.5
IMO--pinentry-mode=loopback
应该--no-symkey-cache
是默认设置。我在这里找到了解决方案https://askubuntu.com/a/1158297/429995并且这里的“匿名”答案(不缓存密码)也很有帮助。
对于 gpg 版本 2.2.4,以下工作使用 symmetric 并将 --batch 添加到gpg命令:
因此,要清除会话中存储的密码,我们可以运行:
echo RELOADAGENT | gpg-connect-agent
本教程中的更多信息:https ://www.baeldung.com/linux/encrypt-decrypt-files