Ala*_*inD 9 git visual-studio-code visual-studio-2019
使用运行 Windows 10 的新工作笔记本电脑,我安装了git
、Visual Studio Code
和Visual Studio 2019
. 在对我的个人 git 存储库(托管在 )中的代码进行一些测试更改后github
,我尝试提交这些更改并将其推送到远程存储库。
我可以执行 中的所有Stage
、Commit
和Push
操作Git Bash
。但在 Git Gui、VS Code 和 VS 2019 中,Stage
两者Commit
都工作正常,但Push
失败并显示错误消息。
对于 VS Code,错误是:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Run Code Online (Sandbox Code Playgroud)
对于 VS 2019,错误类似:
git@github.com: Permission denied (publickey).
Error encountered while pushing to the remote repository: Git failed with a fatal error.
Could not read from remote repository.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
@DaemonPainter 的评论帮助找到了答案。我的 SSH 私钥文件被命名为id_rsa_github
和id_rsa_github.pub
. Visual Studio 2019、Code 和 Git Gui 都希望它们被命名id_rsa
为id_rsa.pub
.
解决方案是添加一个内容类似于以下内容的config
文件:%HOMEPATH%\.ssh
host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_github
Run Code Online (Sandbox Code Playgroud)
进行更改后,git push
可在 Git Bash、Gut Gui、VS Code 和 Visual Studio 中使用。
正如 @DaemonPainter 指出的,一种可能性是 SSH 身份和密钥丢失。对于这个问题,描述如何添加 SSH 密钥的答案可能会令人感兴趣。
我的问题是 SSH 密钥文件的命名。默认情况下,这些文件位于%HOMEPATH%\.ssh
文件名id_rsa
和id_rsa.pub
. 开发人员工具(例如Visual Studio 2019
、 )并Git Gui
期望采用这种命名约定。
由于我的文件用于个人 git 存储库Github
,因此我将 SSH 密钥文件命名为id_rsa_github/.pub
。在 中%HOMEPATH%\.bashrc
,添加了以下几行(最初在另一台 PC 上配置并复制过来):
# Start ssh-agent to allow git to be used
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa_github
Run Code Online (Sandbox Code Playgroud)
这解释了为什么它有效Git Bash
。
要配置非标准命名 SSH 密钥,请按照下列步骤操作:
添加一个名为%HOMEPATH%\.ssh\config
编辑config
类似以下内容(用于#
添加注释):
host github.com
# My personal git repo for (something-cool)
HostName github.com
IdentityFile ~/.ssh/id_rsa_github
Run Code Online (Sandbox Code Playgroud)
重新启动您的开发工具,例如Visual Studio Code
归档时间: |
|
查看次数: |
31406 次 |
最近记录: |