我今天刚刚经历了这个。我假设您已经安装了适用于 Windows 的 Git,并生成了位于用户“.ssh”文件夹中的 ssh 密钥。
之后,您必须在线进入您的 GitHub 帐户中的设置,并在左侧菜单中查找 “SSH 和 GPG 密钥” 选项:
您必须在此处输入您的公钥,方法是打开 "id_rsa.pub" 文件,然后通过单击“新建 SSH 密钥”将其内容复制到您的 GitHub 帐户:
然后,您可以像使用常规 HTTP 连接一样使用 vscode。直接Crtl+Shift+P打开vscode的Command Pallet,选择git:clone,粘贴你想要的GitHub repo的SSH地址。为了在您单击 GitHub 存储库上的绿色“克隆或下载”按钮时获得 SSH 地址,您还必须在弹出的框中单击 “使用 SSH 克隆”,以便复制 SSH 地址而不是使用 HTTPS 链接。
您可能遇到的唯一问题是,第一次在 vscode 中尝试 ssh 时,它会说“无法识别主机”解决此问题的方法是简单地从一个 git clone vscode 之外的 git bash 命令行,因此当它询问您是否可以添加 GitHub 的 SSH 密钥指纹时,您可以键入“yes”。
ROB@WINDOW10 MINGW64 ~/Documents
$ git clone git@github.com:Rob4226/example.git
Cloning into 'Example Repo'...
The authenticity of host 'github.com (140.82.114.3)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? **yes**
Warning: Permanently added 'github.com,140.82.114.3' (RSA) to the list of known hosts.
无论出于何种原因,vscode git 源代码控制 UI 都不会显示此消息以供您响应,因此它只会引发错误。但是在你第一次在 git bash 命令行中说“是”之后,ssh 将从现在开始在 vscode 中正常工作。它工作得很好,而且速度更快!我不再使用 vscode 的 HTTPS。
或者,您可以手动将 GitHub 的 SSH 密钥指纹添加到 .ssh 文件夹中的 "known_hosts" 文件中。他们可以在这里找到:https://help.github.com/en/github/authenticating-to-github/githubs-ssh-key-fingerprints
GitHub's SSH key fingerprints
Public key fingerprints can be used to validate a connection to a remote server.
These are GitHub's public key fingerprints (in hexadecimal format):
16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48 (RSA)
ad:1c:08:a4:40:e3:6f:9c:f5:66:26:5d:4b:33:5d:8c (DSA)
These are the SHA256 hashes shown in OpenSSH 6.8 and newer (in base64 format):
SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 (RSA)
SHA256:br9IjFspm1vxR3iA35FWE+4VTyz1hYVLIE2t1/CeyWQ (DSA)