当我尝试从本地推送到远程 gitlab 存储库时权限被拒绝

Permission denied when I try to push from local to remote gitlab repository

我在 gitlab web 中创建了一个存储库 ui 并尝试推送我的本地存储库。我使用以下命令添加了远程仓库:

$ git remote add origin test@x.x.x.x:project.git

然后我尝试推送但是它出错了。我不使用 ssl。我想使用纯文本连接。

$ git push origin master
test@x.x.x.x's password:
Permission denied, please try again.
test@x.x.x.x's password:
Permission denied, please try again.
test@x.x.x.x's password:
Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Then I created the test user from web ui. and created the project with the test user.

您永远不会使用该用户联系 ssh 中的服务器:所有授权密钥都分组在 一个 帐户下,对于 gitlab 应该是 git~git/.ssh/authorized_keys

config/gitlab.yml

所以尝试:

git remote set-url origin git@x.x.x.x:project.git

默认情况下,较新版本的 ssh 也不允许使用 DSA 密钥。确保您使用的是 RSA 密钥或确保您的 ~/.ssh/config 或 /etc/ssh/ssh_config 文件 允许 DSA 密钥。您可以通过将类似这样的内容添加到适当的文件来完成此操作:

Host your.git.server
    KexAlgorithms +diffie-hellman-group1-sha1
    HostkeyAlgorithms ssh-dss,ssh-rsa

这个有点戳我。

我的一位同事也遇到了同样的问题。对他来说,这是设置 SSH 的问题。似乎使用的凭据不正确。只需清洁即可解决该问题。

$ git config --system --unset credential.helper
$ git config --global --unset credential.helper

感谢 Patthoyts answer