SSH 伺服器接受金鑰,但簽章失敗

SSH 伺服器接受金鑰,但簽章失敗

我最近嘗試從標準 ssh 公鑰設定遷移到使用 GPG 管理我的金鑰。下列的指示在我的發行版的 wiki 上,我設定了使用 sshgpg-agent而不是預設的ssh-agent.我非常確定一切順利:即使~/.ssh刪除了我的目錄,ssh-add -l也會顯示我在 gpg 中為其設定的一個金鑰。

之後,我將遙控器的內容設定~/.ssh/authorized_keys為本地的輸出ssh-add -L,並重新啟動守護程式。

現在嘗試使用連接到我的遙控器ssh -v <myremote>,我收到以下錯誤:

...
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: (none) RSA SHA256:<myfingerprint> agent
debug1: Server accepts key: (none) RSA SHA256:<myfingerprint> agent
sign_and_send_pubkey: signing failed: agent refused operation
debug1: Trying private key: /home/zoickx/.ssh/id_rsa
debug1: Trying private key: /home/zoickx/.ssh/id_dsa
debug1: Trying private key: /home/zoickx/.ssh/id_ecdsa
debug1: Trying private key: /home/zoickx/.ssh/id_ed25519
debug1: Trying private key: /home/zoickx/.ssh/id_xmss
debug1: No more authentication methods to try.
<myremote>: Permission denied (publickey).

顯然,伺服器同意我的公鑰已獲得授權,但由於我不清楚的原因,伺服器拒絕繼續。

如果谷歌搜尋“”,則常見答案sign_and_send_pubkey: signing failed是使用ssh-add添加丟失的私鑰或更改密鑰文件的權限。對於我使用 gpg-agent 的情況來說,這些似乎都沒有幫助。我的金鑰似乎確實可用於 ssh,並且沒有可更改權限的檔案。

我擔心的有幾件事:

  • 我在任何時候都沒有收到 gpg 的 pinentry 提示
  • 公鑰的形式是ssh-rsa <key> (none),以奇怪的“none”而不是標準結尾user@host

有關我的設定的附加資訊:

  • GPG 2.2.15
  • libgcrypt 1.8.4
  • 輸出gpgconf
gpg:OpenPGP:/usr/bin/gpg
gpg-agent:Private Keys:/usr/bin/gpg-agent
scdaemon:Smartcards:/usr/lib/gnupg/scdaemon
gpgsm:S/MIME:/usr/bin/gpgsm
dirmngr:Network:/usr/bin/dirmngr
pinentry:Passphrase Entry:/usr/bin/pinentry
  • gpg 按預期進行加密/解密,並且 pinentry 正常運作
  • 未運行 Gnome 或任何其他桌面環境 - 使用 dwm
  • 海馬已安裝

答案1

由於系統沒有提示您輸入 GPG 密碼,因此問題或許正在運行的 gpg-agent 無法存取顯示/終端。我在使用 GPG 版本 2.2.17 的 Mac OS 10.14 (Mojave) 上遇到了相同的症狀。

我在 gpg-agent 的手冊頁中找到了解決方法:

注意:如果 gpg-agent 收到簽章請求,可能需要提示使用者輸入密碼,這是解密儲存的金鑰所必需的。由於 ssh-agent 協定不包含告訴代理程式在哪個顯示/終端上執行的機制,因此 gpg-agent 的 ssh-support 將使用 gpg-agent 已啟動的 TTY 或 X 顯示。若要將此顯示切換到目前顯示,可以使用以下命令:

     gpg-connect-agent updatestartuptty /bye

雖然我還沒有找到永久的解決方案,但這個命令對我有用。每次重啟後都需要重複。

相關內容