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

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

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

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

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


当前回答

当你有多个git帐户,你想要不同的ssh密钥 您必须遵循生成ssh密钥的相同步骤,但请确保 你

ssh-keygen -t ed25519 -C "your-email-id@gmail.com" 

输入您想要保存的路径(例如:my-pc/Desktop/.ssh/ed25519)

添加公钥到你的gitlab(如何添加ssh密钥到gitlab)

您必须使用下面的命令创建新的ssh标识

ssh-add ~/my-pc/Desktop/.ssh/ed25519

其他回答

我的问题是我使用了一个具有sudo访问权限的非root用户。但即使是sudo git克隆…没有工作。解决方案是为项目创建文件夹,chown用户项目文件夹,然后运行克隆没有sudo。

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

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

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

我添加了~/.ssh/id_rsa。pub到我的GitLab设置中的已知SSH密钥列表https://gitlab.com/profile/keys。这为我解决了问题。: -)

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

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

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

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