git 向 Gitlab 添加了 SSH 密钥,但它仍然要求我提供凭据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29061025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:49:49  来源:igfitidea点击:

Added SSH key to Gitlab but it still asks for my credentials

gitsshgitlabpermission-denied

提问by Jānis Blaus

GitLab's HTTP pull & push are working when I enter my credentials.

当我输入凭据时,GitLab 的 HTTP 拉取和推送正在工作。

But when using an added SSH key, it is always is asking for my password, which I don't know. Why is GitLab doing this? Is it a server fault?

但是当使用添加的 SSH 密钥时,它总是询问我的密码,我不知道。GitLab 为什么要这样做?是服务器故障吗?

And when calling ssh -vT [email protected]there is an error:

调用时ssh -vT [email protected]出现错误:

Permission denied (publickey)

权限被拒绝(公钥)

I've tried everything, even re-installing Git, but nothing works. Even their own solution is not working, as described here: https://help.github.com/articles/error-permission-denied-publickey/

我已经尝试了一切,甚至重新安装了 Git,但没有任何效果。甚至他们自己的解决方案也不起作用,如下所述:https: //help.github.com/articles/error-permission-denied-publickey/

回答by serdroid

I had similiar problem with new installation of gitlab. After some investigation I've seen below message shown in systemctl status sshd:

我在新安装 gitlab 时遇到了类似的问题。经过一番调查,我在 systemctl status sshd 中看到了以下消息:

Accepted publickey for git from 10.x.x.x port 50858 ssh2: RSA 67:01:..

User git from 10.x.x.x not allowed because none of user's groups are listed in AllowGroups

接受来自 10.xxx 端口 50858 ssh2 的 git 公钥:RSA 67:01:..

不允许来自 10.xxx 的用户 git,因为 AllowGroups 中未列出任何用户组

Adding git user into sshusers group solve my problem.
Hope this helps

将 git 用户添加到 sshusers 组解决了我的问题。
希望这可以帮助

回答by Steve TheGreat

I realize this is a superold question, but I will post this regardless.

我意识到这是一个非常古老的问题,但无论如何我都会发布这个。

In my case it was an SELinux issue. Either disable it or ensure that authorized_keys has the SELinux type of ssh_home_twith

就我而言,这是一个 SELinux 问题。禁用它或者保证的authorized_keys已经SELinux的类型ssh_home_t

semanage fcontext -a -t ssh_home_t "/home/git/.ssh/authorized_keys"

semanage fcontext -a -t ssh_home_t "/home/git/.ssh/authorized_keys"

Where /home/gitis the path the git user's home directory. Mine was /var/opt/gitlab/.

/home/gitgit用户主目录的路径在哪里。我的是/var/opt/gitlab/

回答by emonik

I had the same issue, after checking

我有同样的问题,检查后

/var/log/auth.log

I got :

我有 :

*User git not allowed because account is locked
*input_userauth_request: invalid user git [preauth]
*Connection closed by IP.IP.IP.IP [preauth]

So the fix was

所以修复是

sudo passwd -d git

须藤密码 -d git

Thanks to Noah (source)

感谢诺亚(来源)