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

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

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

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

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


当前回答

在我的案例中,它在WSL (Linux的Windows子系统)中不起作用。

当我开始WSL时,我必须

启动ssh-agent_ eval $(ssh-agent -s) 将密钥添加到ssh-agent: ssh-add ~/.ssh/id_rsa 如果有提示,请输入密码

现在连接起作用了。 我们可以使用ssh -T git@github.com进行测试

注:

weasel-pageant允许我们在WSL中重用在PuTTY pageant中加载的ssh密钥 详细解释:Git通过SSH从Windows返回Permission Denied

其他回答

我花了好几个小时才修好的。下面的方法对我很有效。

在终端上执行这些命令。

ssh-keygen -t rsa -C "<your email address>" -b 4096 -t ed25519

将生成的密钥重命名为:id_rsa和id_rsa。将生成的公钥添加到gitlab服务器。

然后将ssh密钥添加到ssh代理,如下所示。

启动ssh-agent Eval "$(ssh-agent -s)" 如果生成的密钥名称不同,请在下面的命令中替换id_rsa ssh-add ~ / . ssh / id_rsa

要测试连接,请使用此命令。

ssh -T git@<git lab server url>

要排除故障,请使用以下命令。

ssh -Tv git@<git lab server url>
ssh -vvv git@<git lab server url>

现在可以将项目克隆到本地环境。

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

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

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

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。这为我解决了问题。: -)

在我们的例子中,这不是用户/客户端的问题,而是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访问就可以了。