GitLab 需要 git@localhost 密码才能推送到仓库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11767366/
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-10 14:16:55  来源:igfitidea点击:

GitLab requires git@localhost password to push to a repo

gitsshgitolitegitlab

提问by DevinR

I'm trying to get GitLab up and running on my server. I followed the installation instructions at the gitlab github page and everything went well.

我正在尝试在我的服务器上启动并运行 GitLab。我按照 gitlab github 页面上的安装说明进行操作,一切顺利。

The issue is, when I create a repo and try to

问题是,当我创建一个回购并尝试

sudo git push -u origin master

I am prompted for 'git@localhost's password: '

系统提示我输入“git@localhost 的密码:”

The git user doesn't have a password, so this is a problem.

git 用户没有密码,所以这是一个问题。

Other people who have run into this problem suggested adding git to AllowedUsers in my sshd conf but I don't have an AllowedUsers field in there, so that doesn't seem to be an issue.

遇到此问题的其他人建议在我的 sshd conf 中将 git 添加到 AllowedUsers 但我在那里没有 AllowedUsers 字段,因此这似乎不是问题。

I'm still pretty new to ssh stuff so I believe its some sort of ssh key issue, though I tried to add all relevant ssh keys to /home/git/.ssh/authorized_keys and verified that there are no line breaks in the file.

我对 ssh 的东西还是很陌生,所以我相信它是某种 ssh 密钥问题,尽管我尝试将所有相关的 ssh 密钥添加到 /home/git/.ssh/authorized_keys 并验证文件中没有换行符.

Just FYI, my install completely passes the test provided in the gitlab wiki:

仅供参考,我的安装完全通过了 gitlab wiki 中提供的测试:

sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production

Any suggestions much appreciated!

任何建议非常感谢!

EDIT

编辑

So, I finally got around this by just committing to a repo from a different machine. As it was, I was SSHed into the same machine that gitlab was running on. As soon as I tried to commit from a machine other than the host, it worked great. So, that may be a solution for some people (it is for us, since we develop on seperate machines than our servers).

所以,我终于通过从另一台机器提交回购来解决这个问题。事实上,我通过 SSH 连接到运行 gitlab 的同一台机器上。当我尝试从主机以外的机器提交时,它工作得很好。所以,这对某些人来说可能是一个解决方案(对我们来说是这样,因为我们在不同的机器上开发而不是在我们的服务器上)。

This is still an open-ended issue for anyone trying to host and develop on the same machine who has run into this.

对于任何试图在同一台机器上托管和开发的人来说,这仍然是一个开放式问题。

回答by RacsO



TL;DR

TL; 博士

Keys store on both gitlab DB and gitolite side. You should use the factory build gitolite-admin.git folder, don't use your backup! And rebuild the Keys for gitolite later with the update keys command. (update those keys already saved inside the gitlab db to gitolite)

密钥存储在 gitlab DB 和 gitolite 端。您应该使用工厂构建的 gitolite-admin.git 文件夹,不要使用您的备份!稍后使用 update keys 命令重建 gitolite 的密钥。(将已保存在 gitlab 数据库中的那些密钥更新​​为 gitolite)

sudo -u gitlab -H bundle exec rake gitlab:gitolite:update_keys RAILS_ENV=production


Most likely it's because there is something issue about the gitolite keys not save properly. Those keys (for login) are actually keep separately by gitlab & gitolite. For pull/push is actually using the keys saved inside gitolite. (git/repositories/gitolite-admin.git/index, git/.gitolite/keydir, git/.ssh/authorized_keys)

很可能是因为 gitolite 密钥存在一些问题,无法正确保存。这些密钥(用于登录)实际上由 gitlab 和 gitolite 分开保存。对于拉/推实际上是使用保存在 gitolite 中的键。(git/repositories/gitolite-admin.git/index, git/.gitolite/keydir, git/.ssh/authorized_keys)

gitlab normally should help on saving those imported keys on web to the gitolite files. However, for some reasons it failed. As the keys are not saved properly inside gitolite, the client/server fail to use the keys and fallback to password.

gitlab 通常应该有助于将 Web 上的那些导入密钥保存到 gitolite 文件中。然而,由于某些原因,它失败了。由于密钥没有正确保存在 gitolite 中,客户端/服务器无法使用密钥并回退到密码。

You have to check and fix those keys saved inside gitolite to correct the problems.

您必须检查并修复保存在 gitolite 中的那些密钥以纠正问题。

check out for more https://groups.google.com/forum/?fromgroups=#!topic/gitlabhq/X0z_9l7L7A8

查看更多 https://groups.google.com/forum/?fromgroups=#!topic/gitlabhq/X0z_9l7L7A8

回答by VonC

If the installation went well, that means your gitlab is able to clone the gitolite-admin repo without issue.
But you say it passes the status check, which means you are using, for ssh connection, an account named 'gitlab'.

如果安装顺利,这意味着您的 gitlab 能够毫无问题地克隆 gitolite-admin 存储库。
但是您说它通过了状态检查,这意味着您正在使用名为“gitlab”的帐户进行 ssh 连接。

That also means that any client will have to ssh with that same account 'gitlab', not 'git'.
So if your ssh key has been added through the gitlab interface, then you can git clone/git push to a remote name origin which would have the address 'gitlab@server'

这也意味着任何客户端都必须使用同一个帐户 ' gitlab' 而不是 ' git'进行 ssh 。
因此,如果您的 ssh 密钥已通过 gitlab 界面添加,那么您可以 git clone/git push 到具有地址 ' gitlab@server'的远程名称来源

To debug some more, check out some other tips mentioned in "Setup Git Remote SSH (git-upload-pack / git-receive-pack)":

要进行更多调试,请查看“设置 Git 远程 SSH (git-upload-pack / git-receive-pack)”中提到的其他一些技巧:

If you cannot push locally (on the server itself, that is on 'localhost'), try at least a:

如果您无法在本地推送(在服务器本身上,即在“本地主机”上),请至少尝试一个:

ssh -vvvT gitlab@localhost

It shouldn't require any password, since /home/gitlab/.ssh/id_rsaand /home/gitlab/.ssh/id_rsa.pubboth exist.

它不应该要求任何密码,因为/home/gitlab/.ssh/id_rsa/home/gitlab/.ssh/id_rsa.pub同时存在。

回答by pixel

I received the same password prompt. My issue was that I had restricted ssh usage to only a couple of users. I added the git user to the AllowUsers list sshd_config, and everything worked great.

我收到了相同的密码提示。我的问题是我将 ssh 的使用限制为只有几个用户。我将 git 用户添加到 AllowUsers 列表 sshd_config,一切都很好。

回答by phone911

Make sure your gitlab profile has your public ssh key. Sign into gitlab, go to your profile and select the button "Add Public Key". Copy and paste you "keyfile".pub contents in the in the Key box. There were some versions of gitlab that had a bug that when you did add your public key, it did not update the authorized_keys file. Verify (but do not manually add) that your public key is in the authorized_keys file after you add it to your profile. If this is not the issue, then perhaps one of the earlier answers will help.

确保您的 gitlab 配置文件具有您的公共 ssh 密钥。登录 gitlab,转到您的个人资料并选择“添加公钥”按钮。将您的“keyfile”.pub 内容复制并粘贴到“密钥”框中。某些版本的 gitlab 存在一个错误,即当您添加公钥时,它没有更新 authorized_keys 文件。将公钥添加到您的配置文件后,验证(但不要手动添加)您的公钥是否在authorized_keys 文件中。如果这不是问题,那么早期的答案之一也许会有所帮助。

回答by Bent Cardan

on the git server edit /etc/ssh/sshd_config

在 git 服务器上编辑 /etc/ssh/sshd_config

uncomment the following lines under the authentication section or add them:

取消注释身份验证部分下的以下行或添加它们:

PubkeyAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile %h/.ssh/authorized_keys

AuthorizedKeysFile %h/.ssh/authorized_keys

give your server a power cycle and then fire up gitlab

给你的服务器一个电源循环,然后启动 gitlab

回答by Michael Durrant

This started happening to me quite a lot lately - for work projects git would ask me my email and password. When entered it continues ok but it's annoying.

这最近开始发生在我身上很多 - 对于工作项目,git 会问我我的电子邮件和密码。进入后,它继续正常,但很烦人。

I can fix this for any given application that I have access to with:

我可以为我有权访问的任何给定应用程序修复此问题:

git config remote.origin.url [email protected]:user_org_or_co/repo_name_itself

e.g.

例如

git config remote.origin.url [email protected]:smithw/bookmarkapp

回答by Mauro Dias

Your git and gitlab users are passwordless?

您的 git 和 gitlab 用户是无密码的吗?

How the sshd_configis?

情况如何sshd_config

check if this line is in the file: PermitEMptyPassword Yes

检查此行是否在文件中: PermitEMptyPassword Yes

Anyway I guess it unsafe, in my installation, I put this 'Yes', clone and then keep the old config... When Cloning the ssh_key is saved by user git, and it will not ask password anymore..

无论如何我猜它不安全,在我的安装中,我把这个'是',克隆然后保留旧配置......当克隆时 ssh_key 被用户 git 保存,它不会再询问密码了..

But by now, i run into another error, when Im going to push, for every new User, we have to reconfig ssh for permit empty push and then keep back the config.

但是现在,我遇到了另一个错误,当我要推送时,对于每个新用户,我们必须重新配置 ssh 以允许空推送,然后保留配置。

(I still haven't tested this method, because I found out that my gitlab isn't creating the repos in git user :/ )

(我还没有测试这个方法,因为我发现我的 gitlab 没有在 git user 中创建 repos :/)

回答by Eebs

I ran into a problem that exhibited similar symptoms. My issue was that I have two computers behind a router. The router is set to port forward SSH traffic (port 22) to computer 1. Gitlab is installed on computer 2. I am using a domain and a public facing IP to connect. When I push, the SSH traffic is directed to computer 1. There is a git user on computer 1 simply from having installed git. Computer 1 prompts me for the git user's password.

我遇到了一个表现出类似症状的问题。我的问题是我在路由器后面有两台计算机。路由器设置为将 SSH 流量(端口 22)端口转发到计算机 1。Gitlab 安装在计算机 2 上。我使用域和面向公众的 IP 进行连接。当我推送时,SSH 流量被定向到计算机 1。计算机 1 上有一个 git 用户,因为安装了 git。计算机 1 提示我输入 git 用户的密码。

My install also passed all the ready checks.

我的安装也通过了所有准备好的检查。

I'm not sure if you're having the same issue, but the symptoms are the exact same so I figured this might help.

我不确定您是否遇到同样的问题,但症状完全相同,所以我认为这可能会有所帮助。

回答by tsar2512

This may be too simple, but I had the same problem. I'm guessing it's because it picked up localhost as the domain name.

这可能太简单了,但我遇到了同样的问题。我猜这是因为它选择了 localhost 作为域名。

It worked out when I logged in from another computer back to my localhost machine, and then tried to commit. It's pretty dumb but worth trying.

当我从另一台计算机登录回我的本地主机,然后尝试提交时,它就成功了。这很愚蠢,但值得一试。

回答by Iszuddin Ismail

I got mixed up with this one time. When you use sudo git, that means the git is being launched as root. The question would be -- did you create SSH key for root and put it inside Gitlab?

有一次我把它搞混了。当您使用 时sudo git,这意味着 git 正在以 root 身份启动。问题是——您是否为 root 创建了 SSH 密钥并将其放入 Gitlab?

I am guessing that you created your SSH key without sudo(which is for your normal account), put the SSH publickey into Gitlab, and then run sudo git.

我猜你创建了你的 SSH 密钥sudo(用于你的普通帐户),将 SSH 公钥放入 Gitlab,然后运行sudo git.

You can try running git without the sudo. And if you have folder permission issues, which made you use sudo in the first place, try giving your user account access to that folder. Or perhaps try the git normally in a folder that you have write permission.

您可以尝试在没有 .git 文件的情况下运行 git sudo。如果您有文件夹权限问题,导致您首先使用 sudo,请尝试授予您的用户帐户访问该文件夹的权限。或者,也许可以在您具有写入权限的文件夹中正常尝试 git。