完成使用 GitLab 的所有必要步骤,这些设置是:
- 按照 this link 中的描述创建了一个 rsa
- 复制在
{my key}.pub
中生成的代码并在GitLab 中添加此代码 - 在我现有的存储库中,使用命令
git remote add gitlab git@gitlab.com:ridermansb/breezenhibernateproblem.git 添加到 url
- 我尝试进行推送
git push -u gitlab master
我的 .ssh/config
Host gitlab.com
HostName gitlab.com
IdentityFile C:\Users\Riderman\.ssh\gitlab_rsa
IdentitiesOnly yes
错误如下:
警告:将“gitlab.com,54.243.197.170”(RSA) 永久添加到已知主机列表中。 权限被拒绝(公钥)。 致命:无法从远程存储库读取。
请确保您拥有正确的访问权限 并且存储库存在。
我制作了一个展示所有步骤的视频:http://www.screenr.com/euVH
我做错了什么?
最佳答案
看到your screencast之后,我看到您没有 %HOME%\.ssh\config
文件。
这很重要,因为:
- 默认情况下,ssh 将在
%HOME%\.ssh\id_rsa(.pub)
中查找公钥/私钥
- 使用类似 scp 的语法(
git@gitlab.com:yourRepo
,以 ':
' 作为分隔符),ssh 可以查找。 ssh/config
文件用于实际公钥/私钥的位置,使用gitlab.com
作为所述config
文件中的条目。
添加 %HOME%\.ssh\config
:
Host gitlab.com
HostName gitlab.com
IdentityFile C:\path\to\.ssh\gitlab_rsa
IdentitiesOnly yes
你的 git push -u gitlab master
会工作。
It turned out它还与正确设置 HOME 有关:
%HOME%
was not correct.
I configured the variable%HOME%
to point to%USERPROFILE%
locally and it worked
Mysygit does set HOME , 但如果你在 git-cmd
session 之外使用 git,那么你有责任正确设置 HOME
。
关于windows - 推送到现有项目时出现 SSH 错误权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20595713/