Mik*_*ink 8 git ssh github visual-studio-code
我使用的是 mac,我想知道如何使用 vscode 通过 ssh 克隆私有 github 存储库?我查看了 code.visualstudio.com/docs/editor/versioncontrol 但找不到任何有关使用 ssh 克隆的信息。
在 vscode 中,我转到左侧的源代码管理图标,然后单击克隆存储库。我进去了git@github.com:username/project
,它说权限被拒绝。我确实生成了公钥和私钥,但在哪里输入它们?
我今天刚刚经历过这个。我假设您已经安装了 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 时,它会说“无法识别主机”。解决此问题的方法是简单地从 vscode 之外的 git bash 命令行进行git 克隆,这样您就可以当它询问您是否可以添加 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.
Run Code Online (Sandbox Code Playgroud)
无论出于何种原因,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)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
36647 次 |
最近记录: |