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

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

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

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

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


当前回答

主要有两点

您必须有id_rsa。Pub和id_rsa(私有)密钥在您的.ssh文件夹中(应该在您的主文件夹中)。如果没有,就创造它,把你的钥匙放在那里)。如果你用不同的密钥文件命名,它就不会起作用 修改“id_rsa”的权限为“chmod 400 ~/.ssh/id_rsa . sh”

其他回答

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

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

步骤要做,得到同样的错误,但我修复了它。 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/id_rsa),

ssh-add ~/.ssh/<your private key>

基本上让ssh-agent来处理它。

此外,您可以永久地添加它。

如何在ubuntu中添加SSH密钥到gitlab帐户?

在项目目录中打开终端。 输入' ssh-keygen -o -t rsa -b 4096 -C "your gitlab email" ',然后按enter键 输入“vim /home/mnbtech/.ssh/id_rsa”。Pub '然后按回车键 (或者手动打开你的'id_rsa. exe '。Pub '从你保存它的地方) SSH密钥将出现。复制这些 转到你的gitlab账户。 单击头像,单击“设置” 在左侧选择SSH-Keys 然后粘贴这些键 点击添加键

SSH-Key将被添加!

(注意,如果您有生成预览SSH密钥和获得拒绝权限(公钥)。您删除您的预览ssh密钥,并生成一个新的,并在您的终端上添加git用户名和电子邮件)

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

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

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