GitLab SSH密钥停止工作

13

好的,我已经多次遇到这个问题了,但这是第一次没有常规解决方案奏效。

我有一个运行GitLab的CentOS 6.4服务器。与20多个用户和60多个项目一起工作得很好,但大约5小时前,我的主要分段服务器无法使用密钥身份验证连接到GitLab机器,并提示输入密码。我重新生成了RSA密钥并将其添加到我的部署密钥,但仍然失败。

接下来,我尝试在分段服务器上创建一个新用户,为其创建密钥并将其添加到GitLab,但它仍然失败。

权限:

drwxr-x---  22 root root 4.0K Oct 28 13:20 root

根目录中:

drwx------   2 root root     4096 Oct 28 11:49 .ssh

在 .ssh 文件夹内:

-rw-------  1 root root  227 Oct 28 11:48 authorized_keys
-rw-------  1 root root 1675 Oct 28 13:09 id_rsa
-rw-------  1 root root  398 Oct 28 13:09 id_rsa.pub
-rw-r--r--  1 root root  413 Oct 28 11:49 known_hosts

当我尝试连接到Git机器时:

OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to git.mygitlab.com [212.29.122.24] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'git.mygitlab.com' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-    mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Offering public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-    mic,password
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
git@git.mygitlab.com's password:
当我通过Web界面添加SSH密钥时,它们没有添加到.ssh/authorized_keys中。 我不知道该尝试什么:(

你能在 git.mygitlab.com:~git/.ssh/authorized_keys 中看到你的公钥吗? - VonC
实际上不是这样的!在GitLab服务器上,我有49个授权密钥文件,当我添加额外的密钥时,它们不会出现。 - SlipY
那就是问题所在。GitLab 中是否有任何日志可以留下线索? - VonC
不幸的是,我重新启动了两台机器... 没有帮助。 - SlipY
这是一个与Gitlab授权密钥文件不同步的问题。由于我正在运行旧版本(4.0),所以我正在逐个版本升级以查看是否已解决。 - SlipY
显示剩余5条评论
5个回答

5
如果你添加到GitLab的密钥没有出现在.ssh/authorized_keys中:
  1. 确保Sidekiq正在运行。 Gitlab-shell中的密钥是在Sidekiq工作进程中添加的,因此如果Sidekiq停止或积压,它们将无法添加。您可以通过检查ps -fu git的输出和检查管理员页面上的“后台作业”选项卡来检查这一点。
  2. 确保GitLab可以正确执行gitlab-shell。 Sidekiq工作程序通过执行gitlab-shell进程添加密钥。特别地,如果在gitlab.ymlssh_user设置不正确,或者gitlab-shell安装到与该用户不同的位置~/gitlab-shell,则此方法将无效。
  3. 验证服务器的/home分区是否已满。 如果存储authorized_keys文件的磁盘已满,则密钥追加将失败!我遇到过几次这种情况。使用df -h /home查看是否还有空间。

请检查gitlab-shell的错误日志:根据问题的不同,错误信息可能会出现在unicorn或sidekiq的日志中。


嗨,Ash, 你是100%正确的,但正如我所说,我正在使用旧版本的Gitlab(4.1),而且我没有gitlab-shell.. 我正在尝试逐个版本升级,直到它更新为最新版本。 - SlipY
哦,对了,我漏掉了那一部分。是的,4.1版本是在gitolite时代发布的。如果您直接拉取gitolite配置存储库,您的密钥是否已经添加到gitolite的设置中?如果没有,有一个Rake任务可以重新同步所有内容:rake gitlab:gitolite:update_keys - Ash Wilson
也有可能是您的gitolite安装出了问题,例如缺少或不可执行的post-receive钩子。请仔细检查您的gitolite安装:https://github.com/sitaramc/gitolite - Ash Wilson

3

好的,现在我已经升级到了5.1版本。我是按照以下步骤进行的:

4.1 > 4.2

4.2 > 4.3

最终,一切都正常运行。

仅供4.1用户参考 - > 开发人员中有一个添加了一个包含$#root...的错误密钥,这就是导致同步中断的原因。

感谢您的帮助。


0

由于我在Cent8上花了很多时间来解决这个问题,所以我想发布解决方案。我尝试了这里的所有方法,但仍然存在问题。我的问题是~git/.ssh/authorized_keys上的SELinux上下文。您可以使用以下命令进行检查:

ls -lZ ~git/.ssh/authorized_keys

然后你会得到类似这样的东西

-rw-------. 1 git git unconfined_u:object_r:ssh_home_t:s0 282 May  5 00:34 .ssh/authorized_keys

我的文件中出现了var_t而不是问题所在的ssh_home_t。 这可以通过解决。

sudo chcon -t ssh_home_t ~git/.ssh/authorized_keys

干杯!


0
不得不删除主机的所有先前密钥。问题是gitlab会接受任何旧密钥,如果匹配项不存在,则会在那里失败。您的有效密钥可能会在后面的顺序中列出,但却从未被选中。

0

当我将GitLab服务器从HTTP切换到HTTPS时,遇到了这个问题。在Web服务器上,一切看起来都很正常 - 登录等都正常工作,但是git@gitlab SSH连接失败。

在查看https://dev59.com/r2Ik5IYBdhLWcg3wDaQW#19637026(上面的#2)后,我发现需要修改/home/git/gitlab-shell/config.yaml中的gitlab_url设置,以使用https://gitlab.server.fqdn而不是http://gitlab.server.fqdn。我更改了该设置,重新启动了gitlab服务,一切正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接