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

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

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

在我的电脑上设置一个SSH密钥,并将公钥添加到GitLab 完成了用户名和电子邮件的config -global 通过SSH和HTTP克隆,以检查它是否能解决问题 执行ssh -T 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/”的位置。

其他回答

早些时候,这对我来说是非常困难的,但当我尝试时,在Mac和Linux中添加ssh密钥变得如此容易。有以下几个步骤和命令可以做到这一点:

打开系统的一个终端,通过下面的命令移动到项目目录中:

cd 'project directory name'

在该终端中运行ssh-keygen命令并输入它,直到密钥的randomart图像出现在那里。 然后在终端上再输入一个命令:

cat ~/.ssh/id_rsa.pub

它将生成ssh密钥。Key将以ssh-rsa开始,以.local结束。

复制密钥并转到您的Gitlab配置文件部分,然后ssh密钥部分并粘贴到那里。点击添加按钮,这将工作。

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

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

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

请使用git配置凭证。如果您的站点使用TLS/SSL, helper存储。 希望这有用

这两种访问git存储库的方式之间似乎存在差异,即使用SSH或HTTPS。对我来说,我遇到这个错误是因为我试图使用SSH推送我的本地存储库。

这个问题可以简单地通过单击项目登录页面上的克隆按钮来解决,复制HTTPS链接并将其替换为格式为“git@gitlab...”的SSH链接。

创建SSH密钥后,您只需要添加公钥,通常命名为:

id_rsa . pub

OR

id_ed25519.pub

通过使用GitLab最新的工作URL:

https://gitlab.com/-/profile/keys/