Mac-Osx

無法使用 gpg-agent 通過 SSH 連接到伺服器

  • May 7, 2020

我正在嘗試連接到 Google Cloud 上的虛擬機。我創建了一個用於 SSH 的公鑰並將該密鑰添加到雲實例。我已SSH_AUTH_SOCK設置為gpg-agent.

~/.gnupg/gpg-agent.conf

default-cache-ttl 600
max-cache-ttl 7200
enable-ssh-support
pinentry-program /usr/local/MacGPG2/libexec/pinentry-mac.app/Contents/MacOS/pinentry-mac
~/.zprofile

...

export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent

一切似乎都正常工作:

% ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EA... (none)

但是,當我嘗試實際連接到虛擬機時…

debug1: Offering public key: (none) RSA SHA256:[REDACTED] agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/alice/.ssh/id_rsa
debug3: no such identity: /Users/alice/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /Users/alice/.ssh/id_dsa
debug3: no such identity: /Users/alice/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /Users/alice/.ssh/id_ecdsa
debug3: no such identity: /Users/alice/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/alice/.ssh/id_ed25519
debug3: no such identity: /Users/alice/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /Users/alice/.ssh/id_xmss
debug3: no such identity: /Users/alice/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
alice@1.2.3.4: Permission denied (publickey).
%

所以,顯然我需要~/.ssh/authorized_keys在伺服器端添加公鑰。我最初是通過基於 Web 的管理控制台在標有“ SSH 密鑰”的部分下添加密鑰的。我仍然不知道為什麼這似乎不起作用。

引用自:https://serverfault.com/questions/1012182