如何防止 gpg-agent 在密碼收集期間逾時?

如何防止 gpg-agent 在密碼收集期間逾時?

gpg2我在 CLI 腳本中呼叫對本地文件進行對稱加密。它似乎gpg-agent透過一些 CLI、基於文字的 UI 提示輸入密碼。只要我輸入密碼,一切都正常。但是,如果我不這樣做,它最終會失敗並顯示以下訊息:

gpg-agent[15338]: command get_passphrase failed: Operation cancelled
gpg: cancelled by user
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of `XXXX.tar' failed: Operation cancelled

有什麼辦法可以完全關閉這個超時嗎?

我希望密碼提示無限期地保留在螢幕上,直到我輸入某些內容。

答案1

解決方案已在這裡找到:https://dev.gnupg.org/T3240

延遲是由 pinentry 查詢 GNOME 金鑰環引起的。添加no-allow-external-cache到您的gpg-agent.conf,或刪除gnome-keyring,並終止目前正在運行的 gpg-agent:gpgconf --kill gpg-agent

答案2

在 gpg-agent.conf 中(參見gpg-代理(1)),嘗試以下選項:

pinentry-timeout 0
pinentry-program /usr/bin/pinentry-curses --timeout 0

(不過你可能會發現pinentry-tty使用起來更好一些。)

答案3

問:「如何防止 gpg-agent 在密碼收集期間逾時?

gpg答:具體情況是在會話中使用ssh。以下配置啟用gpg-代理也在一個ssh會話內。尤其

  • 禁止搶奪允許剪下和貼上
  • 不允許外部快取停用任何鑰匙圈
  • pinentry-詛咒要求在終端機中輸入密碼而不是預設密碼皮恩特里在遠端(如果是 ssh)桌面視窗中詢問。
  • 活著的時間TTL(5,6) 設定為 24 小時。這樣,當每天執行使用 gpg-agent 呼叫腳本的 cron 時,就無需重新輸入密碼。
shell> cat ~/.gnupg/gpg-agent.conf
no-grab 
no-allow-external-cache 
pinentry-program /usr/bin/pinentry-curses
default-cache-ttl 86400
max-cache-ttl 86400

答案4

對我有用的(gpg 2.1.11)只是將選項設為pinentry-timeout一個大值(例如 24 小時),方法是將以下內容添加到我的~/.gnupg/gpg-agent.conf文件中:

# time until pinentry closes in seconds
pinentry-timeout 86400

相關內容