
當將 gpg-agent 與 git tag -u 一起使用時,我立即收到以下錯誤:
gpg: cancelled by user
gpg: skipped "[email protected]": bad passphrase
gpg: signing failed: bad passphrase
error: gpg failed to sign the data
error: unable to sign the tag
gpg-agent.conf:
pinentry-program /usr/bin/pinentry-curses
當我先解鎖密鑰(透過 a gpg -e -s test.txt
)時,git tag -u
命令會拾取密鑰並按預期簽署標籤。
這是在 ubuntu 13.10 上,使用 i3 wm。我懷疑 gnome-keyring 會以某種方式妨礙...某些東西,但是在運行 archlinux-arm 的樹莓派上,它的工作方式相同,但問題略有不同 - 運行命令後git tag -u
,它要求解鎖密碼,但沒有密碼輸入或提示出現。一段時間(大約 30 秒)後,它會失敗並顯示以下內容:
gpg: problem with the agent: Line passed to IPC too long
gpg: skipped "[email protected]": Operation cancelled
gpg: signing failed: Operation cancelled
error: gpg failed to sign the data
error: unable to sign the tag
同樣,一旦我直接使用任意文件解鎖密鑰gpg -s
以將憑證緩存在 gpg-agent 中,標籤就可以順利簽署。
我的假設是我對 pinentry-curses 的使用有些奇怪。我已經更新了 /usr/bin/pinentry 以指向 /usr/bin/pinentry-curses,但問題仍然存在。
我做錯了什麼,如何讓 git 與 gpg/pinentry 很好地配合?
- ubuntu gpg 版本:1.4.14
- archlinux-arm gpg 版本:gnupg-2.0.22-1
編輯:運行 zsh。以下是 gpg 代理的相關資訊:
if [ $EUID -ne 0 ] ; then
envfile="$HOME/.gnupg/gpg-agent.env"
if [[ -e "$envfile" ]] && kill -0 $(grep GPG_AGENT_INFO "$envfile" | cut -d: -f 2) 2>/dev/null; then
eval "$(cat "$envfile")"
else
eval "$(gpg-agent --daemon --write-env-file "$envfile")"
fi
export GPG_AGENT_INFO # the env file does not contain the export statement
fi
當我關注 $(tty) (例如/dev/pts/16
:)時,所有權已經是user:tty
。
答案1
您還需要匯出GPG_TTY每次啟動新的 TTY 時都會變數(也可以從 bash/zsh rc 檔案完成):
export GPG_TTY=$(tty)
答案2
Pinentry ncurses 對話方塊的問題與 Pinentry 嘗試使用的 TTY 的所有權有關(例如,如果您最初以使用者身分登錄,然後使用 su )。
將以下腳本放入/etc/profile.d/gpg-agent.sh修復它(您可能想要if
在多用戶系統上省略外部或將條件更改為 != ):
if [ "$(id -un)" = "root" ] ; then
envfile="$HOME/.gnupg/gpg-agent.env"
if [[ -e "$envfile" ]] && kill -0 $(grep GPG_AGENT_INFO "$envfile" | cut -d: -f 2) 2>/dev/null; then
eval "$(cat "$envfile")"
else
eval "$(gpg-agent --daemon --enable-ssh-support --write-env-file "$envfile")"
fi
export GPG_AGENT_INFO # the env file does not contain the export statement
export SSH_AUTH_SOCK # enable gpg-agent for ssh
GPG_TTY=$(tty)
chown $USER:tty $GPG_TTY # make pinentry-ncurses work
fi