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

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

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

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

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


当前回答

在我的情况下,我使用Ubuntu有两个用户,一个是管理员用户,另一个是我,我创建了“id_rsa”和“id_rsa”。Pub”文件,而登录为我(普通用户),这些文件创建在您的”。home文件夹中的Ssh文件夹, 它可能找不到,因为它是隐藏的,所以让它可见,以检查文件是否在其中。

所以文件是在“home/”中创建的。但当我把代码推到gitlab时,我在终端上以管理员身份登录, 使用命令:su - adminName(提示输入密码)

因此“adminhome/”中没有SSH私钥。文件夹。要解决这个问题,你可以:

创建“id_rsa”和“id_rsa”。Pub”在管理配置文件(或)中 使用您的配置文件而不是管理员配置文件将代码推入gitlab。

其他回答

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

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".

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

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

这个方法对我很有用。

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

我是这样解决的。

使用此命令生成Windows密钥:

ssh-keygen -t rsa -C "your.email@example.com" -b 4096

但问题是,在运行这个命令后,它弹出了一行: 输入保存密钥的文件(/c/Users/xxx/.ssh/id_rsa): " 在这里,我只给文件名,因为我的密钥被保存在我的pwd,而不是在给定的位置。当我做“git克隆”时,它假设键位于“/c/Users/xxx/”。Ssh /id_rsa”的位置,但没有找到,因此抛出错误。

在密钥生成时,生成了2个文件,即“file1”和“file1.pub”。我将这两个文件重命名为

file1 -> id_rsa 

and

file1.pub -> id_rsa.pub

并将它们放在“/c/Users/xxx/.ssh/”的位置。

我遇到这个问题是因为Windows-10上的ssh-agent冲突。 如果你也在使用Windows-10,那么请仔细阅读我的详细解决方案

如果你不在windows-10,那么请检查是否:

您的ssh代理正在运行 将正确的私钥添加到ssh-agent中 正确的公钥被添加到你的github帐户(你可以克隆,所以这一步应该是好的)