我的问题是我不能从GitLab中push或fetch。但是,我可以克隆(通过HTTP或SSH)。当我试图推的时候,我得到这个错误:

权限被拒绝(publickey)致命:无法从远程存储库读取

从我看过的所有线索来看,以下是我所做的:

在我的电脑上设置一个SSH密钥,并将公钥添加到GitLab 完成了用户名和电子邮件的config -global 通过SSH和HTTP克隆,以检查它是否能解决问题 执行ssh -T git@gitlab.com命令

如果您对如何解决我的问题有任何见解,我将不胜感激。


当前回答

另一个可能导致这种行为的问题是当你有2个可能的%HOME%-locations的设置时。

我使用的是个人电脑,其中一些文档存储在本地,另一些存储在网络驱动器上。一些应用程序认为C:\Users\<MyUserName>\是my %home%,另一些应用程序认为U:\是home。

原来ssh-keygen把我的私钥放在C:\users\<MyUserName>\下,ssh -T和ssh -v也在那里查找。

所以一切似乎都很好,除了git克隆,git推和其他人在U:\寻找一个键。 它失败了,所以我得到了前面提到的错误。

我花了一个小时才找到答案,但最终解决方案很简单:我复制了C:\Users\<MyUserName>\中的所有内容。ssh到U:\.ssh

其他回答

确保您没有运行sudo git克隆git@gitlab.com:project/ something .git,否则SSH将在/root/中查找。SSH,而不是您上传的密钥~/.ssh/id_rsa

我找了很久才找到这个。这对我来说是完美的。

Go to "Git Bash" just like cmd. Right click and "Run as Administrator". Type ssh-keygen Press enter. It will ask you to save the key to the specific directory. Press enter. It will prompt you to type password or enter without password. The public key will be created to the specific directory. Now go to the directory and open .ssh folder. You'll see a file id_rsa.pub. Open it on notepad. Copy all text from it. Go to https://gitlab.com/-/profile/keys or Paste here in the "key" textfield. Now click on the "Title" below. It will automatically get filled. Then click "Add key".

现在试一试,肯定会管用的。

在我的例子中,在更新到12.9.2之后,我需要更新我的sshd_config文件以使用Authorized command keys指令。

这里的文档解释了一切: https://docs.gitlab.com/ee/administration/operations/fast_ssh_key_lookup.html

当我重新启动ssh时,密钥完美地工作了。

对于任何使用Windows 10且没有其他工作的人:

在我的情况下,我不得不用https而不是ssh克隆回购,并弹出一个窗口,要求我的凭证。 在那之后一切都很好。

修改权限::chmod 400 ~/.ssh/id_rsa 这对我很有帮助。