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

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

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

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

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


当前回答

我解决了git@gitlab.com:权限拒绝(公钥)问题使用以下说明

运行cat ~/.ssh/id_rsa.pub id_rsa副本。pub(公钥)到您的getlab '设置-> SSH密钥 运行cat ~/.ssh/id_rsa 将id_rsa(私钥)拷贝到“Code_repo->git_auth->id_rsa”

注意:如果您在DockerFile或其他任何地方使用root用户,请注意机器用户,然后在运行上述命令之前使用sudo su来获取root用户的公钥和私钥。

其他回答

另一个可能导致这种行为的问题是当你有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

使用cd路径/to/project进入终端工程目录 运行ssh - keygen 按enter键输入密码 执行命令cat ~/.ssh/id_rsa。终点站酒吧 复制你在终端上得到的密钥 进入Gitlab/Settings/SSH-KEYS 粘贴键并按添加键按钮

这对我来说就像一个咒语!

步骤要做,得到同样的错误,但我修复了它。 Gitlab需要ssh-rsa,所以下面是运行ssh for rsa的代码

ssh-keygen -o -t rsa -b 4096 -C "name@gmail.com"

name@gmail.com是您的gitlab帐户电子邮件

It will prompt you to enter so just hit Enter after the below code is prompt, Enter file in which to save the key (/home/yourDesktopName/.ssh/id_rsa): It will prompt again you to enter so just hit Enter after the below code is prompt, Enter passphrase (empty for no passphrase): It will prompt again for the last you to enter so just hit Enter after the below code is prompt, Enter same passphrase again: You will show your ssh-rsa generate. Login to your Gitlab account and Go to the right navbar you will get setting and in the left sidebar you will get ssh key. Enter in it. Look above the prompt asking you to enter, you will get the path of ssh-rsa. Go to your SSH folder and get the id_rsa.pub Open it and get the key and Copy Paste to the Gitlab and you are nearly to done. Check by: ssh -T git@gitlab.com You will get: Welcome to GitLab, @joy4! Done.

这个方法对我很有用。

添加SSH / rsa密钥到gitlab Ssh-add(输入您的终端) - ssh - vt git@gitlab.com

我使用ubuntu 18.04,这实际上是我本地机器的权限问题。当我为我的.git文件夹设置读/写权限时,这个问题就消失了。