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

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

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

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

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


当前回答

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

其他回答

步骤1: 在~/中添加了一个配置文件。Ssh /config文件,看起来像

   User git
   Hostname gitlab.com
   IdentityFile ~/.ssh/id_rsa_gitlab
   TCPKeepAlive yes
   IdentitiesOnly yes

步骤2:克隆没有sudo的git repo。 文档:https://gitlab.com/help/ssh/README working-with-non-default-ssh-key-pair-paths

**有时在~/中有配置。ssh/config,但是,IdentityFile路径错误。您可以像这样检查文件名ls ~/.ssh/。gitlab的文件通常是id_ed25519。因此正确的配置是IdentityFile ~/.ssh/id_ed25519

尝试使用git克隆XXX,如果你看到LibreSSL SSL_connect: SSL_ERROR_SYSCALL连接到XXX,这可能是刚刚更新了你的操作系统,安装了一些开发工具,例如Xcode及其Mac上的工具,VPN,反病毒(特别是卡巴斯基反病毒)或其他之间的东西。

在我的情况下,简单地重新启动我的操作系统(macOS Catalina)修复了这个问题。

我是这样解决的。

使用此命令生成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/”的位置。

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

我解决了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用户的公钥和私钥。