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

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

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

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

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


当前回答

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

在终端上执行这些命令。

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>

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

其他回答

我也有同样的问题,我通过添加一个新的ssh密钥来解决它:

ssh-keygen -t ed25519 -C "email@example.com" 将您的公共SSH密钥复制到剪贴板(xclip -sel clip < ~/. SSH /id_ed25519. exe)。pub在我的情况下在Linux上) 在gitlab上,转到settings=>ssh keys,然后跳过新密钥

如何在ubuntu中添加SSH密钥到gitlab帐户?

在项目目录中打开终端。 输入' ssh-keygen -o -t rsa -b 4096 -C "your gitlab email" ',然后按enter键 输入“vim /home/mnbtech/.ssh/id_rsa”。Pub '然后按回车键 (或者手动打开你的'id_rsa. exe '。Pub '从你保存它的地方) SSH密钥将出现。复制这些 转到你的gitlab账户。 单击头像,单击“设置” 在左侧选择SSH-Keys 然后粘贴这些键 点击添加键

SSH-Key将被添加!

(注意,如果您有生成预览SSH密钥和获得拒绝权限(公钥)。您删除您的预览ssh密钥,并生成一个新的,并在您的终端上添加git用户名和电子邮件)

我使用ubuntu 18.04,这实际上是我本地机器的权限问题。当我为我的.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@gitlab.com:权限拒绝(公钥)问题使用以下说明

运行cat ~/.ssh/id_rsa.pub id_rsa副本。pub(公钥)到您的getlab '设置-> SSH密钥 运行cat ~/.ssh/id_rsa 将id_rsa(私钥)拷贝到“Code_repo->git_auth->id_rsa”

注意:如果您在DockerFile或其他任何地方使用root用户,请注意机器用户,然后在运行上述命令之前使用sudo su来获取root用户的公钥和私钥。