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

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

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

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

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


当前回答

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

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

cd 'project directory name'

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

cat ~/.ssh/id_rsa.pub

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

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

其他回答

我也有同样的问题,在尝试了@Khan的答案后,我提出了这个问题。然而,我只能通过将.git/config文件中的原始url更改为https地址:https://gitlab.com/mygitlabusername/mygitproject.git来使其工作

由于通过ssh访问被拒绝,我发现使用https应该不是问题。但是,每次推送到at存储库时,它都会要求您提供用户名和密码

我使用ubuntu 18.04,这实际上是我本地机器的权限问题。当我为我的.git文件夹设置读/写权限时,这个问题就消失了。

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

id_rsa . pub

OR

id_ed25519.pub

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

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

在我们的例子中,这不是用户/客户端的问题,而是Gitlab服务器端的问题。

我们在CentOS 7.1上运行本地Gitlab CE 12.9实例。

我们发现在服务器上,.ssh/authorized_keys文件没有正确更新。用户创建他们的SSH密钥(遵循Gitlab指南)并将其添加到Gitlab服务器,但服务器不更新authorized_keys,因此总是会导致权限拒绝错误。

一个解决方法是通过运行以下命令重建authorized_keys文件:

$ sudo gitlab-rake gitlab:shell:setup

这适用于任何在运行rake任务之前添加密钥的人。对于下一个要添加密钥的用户,必须有人再次手动运行rake任务。

一个更持久的解决方案是不使用authorized_keys文件,而是在Gitlab数据库上使用索引查找:

GitLab Shell provides a way to authorize SSH users via a fast, indexed lookup to the GitLab database. GitLab Shell uses the fingerprint of the SSH key to check whether the user is authorized to access GitLab. Add the following to your sshd_config file. This is usually located at /etc/ssh/sshd_config, but it will be /assets/sshd_config if you're using Omnibus Docker: Match User git # Apply the AuthorizedKeysCommands to the git user only AuthorizedKeysCommand /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell-authorized-keys-check git %u %k AuthorizedKeysCommandUser git Match all # End match, settings apply to all users again Reload OpenSSH: # Debian or Ubuntu installations sudo service ssh reload # CentOS installations sudo service sshd reload Confirm that SSH is working by removing your user's SSH key in the UI, adding a new one, and attempting to pull a repo.

默认情况下(我们安装时的默认情况),在Admin Area > Performance Optimization设置中检查了Write to authorized_keys文件。因此,我们未选中该选项,转而使用Gitlab数据库。

在设置了索引查找并取消对Write to authorized_keys文件的检查之后,SSH访问就可以了。

我也有同样的问题, 在我重新生成。ssh文件夹内的ssh密钥而没有命名它(保持它为id_rsa.pub)后,它已被修复。 然后再次添加到gitlab ssh key。 现在一切正常。