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

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

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

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

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


当前回答

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

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

其他回答

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

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

cd 'project directory name'

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

cat ~/.ssh/id_rsa.pub

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

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

我在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

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

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

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

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

这个方法对我很有用。

添加SSH / rsa密钥到gitlab Ssh-add(输入您的终端) - ssh - vt git@gitlab.com

另一个可能导致这种行为的问题是当你有2个可能的%HOME%-locations的设置时。

我使用的是个人电脑,其中一些文档存储在本地,另一些存储在网络驱动器上。一些应用程序认为C:\Users\<MyUserName>\是my %home%,另一些应用程序认为U:\是home。

原来ssh-keygen把我的私钥放在C:\users\<MyUserName>\下,ssh -T和ssh -v也在那里查找。

所以一切似乎都很好,除了git克隆,git推和其他人在U:\寻找一个键。 它失败了,所以我得到了前面提到的错误。

我花了一个小时才找到答案,但最终解决方案很简单:我复制了C:\Users\<MyUserName>\中的所有内容。ssh到U:\.ssh