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

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

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

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

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


当前回答

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

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".

现在试一试,肯定会管用的。

其他回答

在我的案例中,它在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

步骤1: 在~/中添加了一个配置文件。Ssh /config文件,看起来像

   User git
   Hostname gitlab.com
   IdentityFile ~/.ssh/id_rsa_gitlab
   TCPKeepAlive yes
   IdentitiesOnly yes

步骤2:克隆没有sudo的git repo。 文档:https://gitlab.com/help/ssh/README working-with-non-default-ssh-key-pair-paths

**有时在~/中有配置。ssh/config,但是,IdentityFile路径错误。您可以像这样检查文件名ls ~/.ssh/。gitlab的文件通常是id_ed25519。因此正确的配置是IdentityFile ~/.ssh/id_ed25519

我也有同样的问题, 在我重新生成。ssh文件夹内的ssh密钥而没有命名它(保持它为id_rsa.pub)后,它已被修复。 然后再次添加到gitlab ssh key。 现在一切正常。

主要有两点

您必须有id_rsa。Pub和id_rsa(私有)密钥在您的.ssh文件夹中(应该在您的主文件夹中)。如果没有,就创造它,把你的钥匙放在那里)。如果你用不同的密钥文件命名,它就不会起作用 修改“id_rsa”的权限为“chmod 400 ~/.ssh/id_rsa . sh”

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

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

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

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

Chown git:users authorized_keys