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

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

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

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

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


当前回答

在我的例子中,这不是一个gitlab问题,而是一个sshd配置问题。除了用户列表之外,ssh服务器不允许连接。用户git,即远程连接到gitlab的用户,不在该列表中。所以,先检查这个。

您可以在/etc/ssh/sshd_config中查看您的ssh服务器配置。如果你有一行AllowUsers选项,添加git到它:

AllowUsers user1 user2 user3 git

其他回答

我在gitlab help中找到了解决方案。

To create a new SSH key pair: 
 1. Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
 2. Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com"
 2.1 Or, if you want to use RSA: ssh-keygen -o -t rsa -b 4096 -C "email@example.com"
 3. Next, you will be prompted to input a file path to save your SSH key pair to... use the suggested path by pressing Enter
 4. Once the path is decided, you will be prompted to input a password to secure your new SSH key pair. It's a best practice to use a password, but it's not required and you can skip creating it by pressing Enter twice.
 5. Copy your public SSH key to the clipboard by using one of the commands below depending on your Operating System:
        macOS:        pbcopy < ~/.ssh/id_ed25519.pub
        WSL / GNU/Linux (requires the xclip package):      xclip -sel clip < ~/.ssh/id_ed25519.pub
        Git Bash on Windows:      cat ~/.ssh/id_ed25519.pub | clip
 6. Navigating to SSH Keys and pasting your public key in the Key field
 7. Click the Add key button

我希望它能帮助到你们中的一些人!

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

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

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

这可能听起来很愚蠢,但请确保您的系统和git客户端使用相同的ssh客户端。这在Windows上可能是最相关的。

当您安装现代版本的Windows时,默认情况下会安装OpenSSH客户端,而当您为Windows安装Git时,它在内部使用自己捆绑的ssh客户端。因此,您需要将Git for Windows指向您的OpenSSH安装。

对于任何其他第三方ssh客户端也是一样的,我们在这里只选择OpenSSH作为我们的客户端。

Win + R => cmd 如果安装了OpenSSH路径 Win + S => '编辑环境变量 系统变量=>查找GIT_SSH密钥 编辑或创建(如果不存在),将其值设置为OpenSSH path 创建一个新的终端实例,现在应该在其中应用更改,这样就可以继续了。

注意,如果你使用的是VS Code或其他具有集成终端的编辑器,仅仅创建一个新的编辑器是不够的,你需要重新启动你的编辑器。

有一个非常简单的解决方案: 与其使用SSH,不如使用https。 这样做: 在项目文件夹中有一个。git文件夹 在那里-你有一个配置文件-在文本编辑器中打开它 改变这条线

url = git@gitlab。com: yourname / yourproject git。

to

Url = https://gitlab.com/yourname/yourproject.git