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

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

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

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

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


当前回答

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

其他回答

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

我有gitlab运行docker,这是我所做的解决我的问题。

发现在docker /var/log/gitlab/sshd/current内部出现了多条消息:

身份验证被拒绝:文件/var/opt/gitlab/.ssh/authorized_keys的所有权或模式错误

之后,我将该文件的所有权从99:users更改为git:users:

Chown git:users authorized_keys

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

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帐户,你想要不同的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

在我的情况下,我使用Ubuntu有两个用户,一个是管理员用户,另一个是我,我创建了“id_rsa”和“id_rsa”。Pub”文件,而登录为我(普通用户),这些文件创建在您的”。home文件夹中的Ssh文件夹, 它可能找不到,因为它是隐藏的,所以让它可见,以检查文件是否在其中。

所以文件是在“home/”中创建的。但当我把代码推到gitlab时,我在终端上以管理员身份登录, 使用命令:su - adminName(提示输入密码)

因此“adminhome/”中没有SSH私钥。文件夹。要解决这个问题,你可以:

创建“id_rsa”和“id_rsa”。Pub”在管理配置文件(或)中 使用您的配置文件而不是管理员配置文件将代码推入gitlab。