
情境
我想使用 GPG 身份驗證子金鑰而不是 SSH 金鑰。
我還想用來gpg-agent
管理這些金鑰的密碼快取。
我在無頭環境中運行,所以我想用於pinentry-curses
我的密碼輸入程序,但我對在無頭環境中工作的任何東西都很好。
我的開發工作流程是這樣的,我在多個會話和窗格中工作tmux
,並且需要能夠git push
從其中任何一個會話和窗格中進行工作。
問題
當我嘗試這樣做時就會出現問題。它不是pinentry
在我目前的窗格中彈出,而是在隨機的其他窗格中彈出(或者有時可能根本沒有窗格,但可能有太多窗格無法搜尋)。為了解決這個問題,我需要殺死該窗格,pinentry-curses
即使如此,它有時仍然會失敗。
我嘗試過的
我嘗試過的配置
我目前的配置如下,儘管我在過去幾週嘗試了很多方法來嘗試使其正常工作。
# ~/.zshrc
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
if [[ $SSH_AUTH_SOCK == /tmp/* ]]; then
ln -sf $SSH_AUTH_SOCK $HOME/.ssh-agent-sock
export SSH_AUTH_SOCK=$HOME/.ssh-agent-sock
fi
export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye >/dev/null
# ~/.gnupg/gpg-agent.conf
pinentry-program /usr/sbin/pinentry-curses
default-cache-ttl 600
max-cache-ttl 7200
enable-ssh-support
# ~/.gnupg/gpg.conf
use-agent
# ~/.gnupg/sshcontrol
MYFINGERPRINTS
# ~/.ssh/config
Host localhost
ForwardAgent yes
AddKeysToAgent ask
我嘗試過的鏈接
- gpg2 pinentry 在沒有 X 的情況下失敗
- SSH、tmux 和 GnuPG 代理的最佳實踐
- Pinentry 使用 gpg-agent 和 SSH 失敗
- https://wiki.archlinux.org/index.php/GnuPG#SSH_agent
- https://gist.github.com/andrewlkho/7373190
- https://www.linode.com/docs/security/authentication/gpg-key-for-ssh-authentication/
- https://opensource.com/article/19/4/gpg-subkeys-ssh
更新:工作配置(再次感謝@SystematicFrank)
# ~/.zshrc
export GPG_TTY=$(tty)
# ~/.gnupg/gpg-agent.conf
pinentry-program /usr/bin/pinentry-curses
default-cache-ttl 600
max-cache-ttl 7200
enable-ssh-support
# ~/.gnupg/gpg.conf
use-agent
# ~/.gnupg/sshcontrol
MYFINGERPRINTS
# ~/.ssh/config
Host localhost
ForwardAgent yes
AddKeysToAgent ask
Match host * exec "gpg-connect-agent UPDATESTARTUPTTY /bye"
答案1
gpg-connect-agent updatestartuptty
問題是每次打開終端時都會調用,因此 pinentry 將自身指向最新的 shell。
您真正想要的不是最新的 shell 終端,而是您正在連接的終端機(呼叫 ssh 時)
為此,最簡單的方法是告訴 .ssh/config 從您正在連接的 tty 執行更新命令。這是你缺少的神奇線條:
Match host * exec "gpg-connect-agent UPDATESTARTUPTTY /bye"