GitLab:无法将代码推送到服务器?

7
我已在Ubuntu服务器上安装了GitLab,除了无法推送/拉取/克隆到/从服务器外,一切似乎都正常运行。当我推送时,会收到一般的错误信息:
fatal: Could not read from remote repository.

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

我尝试了数小时的谷歌搜索,但似乎找不到问题所在。

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

运行良好,全面OK!

我可以通过SSH进入git@adress.adress 我得到:

PTY allocation request failed on channel 0
Welcome to GitLab, Anonymous!

When I do:

ssh git@adress.adress "ls /location/of/git/dir"

我得到:
Not allowed command

网站正在运行,当我在该网站上创建仓库时,它会出现在 /home/git/repository/ 目录下。但我仍然无法向其推送代码。 我遵循了这个指南:

https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md

以及在Apache上运行的指南:

http://shanetully.com/2012/08/running-gitlab-from-a-subdirectory-on-apache/


你是否将你的SSH公钥添加到GitLab中?如果它将你识别为匿名用户,我会认为匿名用户没有对任何仓库的读/写/创建访问权限。 - jeremy
是的,我做了。我不知道它是否应该说匿名,但是当我这样做时,我没有得到密码检查。 - Joakim Engstrom
希望我能提供更多帮助。你正在使用比我更新的gitlab版本,并且他们已经从我熟悉的gitolite切换到了自己的系统。抱歉。 - jeremy
我也希望你能帮我更多。我不知道问题是什么。但别担心。希望有一天我能解决它。 - Joakim Engstrom
无法推送到新的GitLab安装。 - Paul Verest
我发现如果在密钥生成中没有添加我的GitLab密码,它就无法识别我...尝试了这个页面上的所有其他方法...最终这个方法起作用了... - davaus
6个回答

7

在经过多个小时的调试之后,我终于找到了问题所在。我知道配置中肯定有一个简单的问题。

由于第二个指南提到了如何使用相对URL在Apache上设置Gitlab,因此您实际上需要在Gitlab内进行更多的配置。 我取消了unicorn.rb中有关相对URL的注释行, 并在gitlab-shell/config中添加了我的整个URL(包括子目录)。

修改前:

 http://web-adress.com/

之后:

 http://web-adress.com/subdomain/

现在它表现得非常好。

1
嗨,我也遇到了同样的问题,但我不明白你所说的“我添加了整个Before...”是什么意思。 - epsilones
更新了答案。希望现在更有意义了。 - Joakim Engstrom
你把它称为子域名,但实际上它是子目录。这只会增加混淆。你肯定是指子目录吧? - zigojacko
@zigojacko 您是正确的,已经更改了。在答案中混淆了术语。 - Joakim Engstrom

4
您可以使用以下命令进行测试。登录后,它应该显示您的姓名。
ssh -T git@myserver.com
欢迎来到GitLab,Christian Hammer!
如果它显示“欢迎来到GitLab,匿名用户!”,则表示GitLab不认识您是GitLab的用户。

2
当我尝试运行 ssh -T git@myserver.com 时,它没有任何输出,就像什么也没发生一样,直接回到了我的 shell。 - trusktr
我的也是一样的。我不认为gitlab可以在git@mydomain.com上访问。我正在使用一个与apache分开的端口运行。 - Native Coder

2

我不知道你是否已经解决了这个问题,但我发现如果我使用在GitLab中使用的电子邮件地址生成密钥,则该过程可以正常工作。我采取的步骤如下:

ssh-keygen -t rsa -C "#email address#"

使用提供的电子邮件创建新的SSH密钥。

生成公共/私有RSA密钥对。

接下来,只需使用以下代码来转储您的公钥并将其添加到GitLab SSH密钥中。

cat ~/.ssh/#key name#.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....*

我在四月份修复了这个问题并回答了这个问题。但还是谢谢你的提示 ;) - Joakim Engstrom
这对我起作用,与评论中的电子邮件地址无关。我生成了一个新的密钥,然后它就可以工作了。我的先前设置一定是有问题的,因为我一直看到的是“欢迎来到 GitLab,匿名用户!” 然后我才能看到我的名字。 - Newalp

2
更确切地说,关于接受的答案(“由Joakim Engstrom于4月6日回答”和“于7月21日10:07进行编辑”):您很可能处于将Gitlab更新以适合自己的上下文路径的情况中(即从http://localhost/<my_context_path>而不是http://localhost访问它)。在这些操作指南中,并未提到也需修改此gitlab-shell配置文件。请注意保留html标记。
// logout any Gitlab open session, stop your Gitlab service, and your possible third-party webserver first  
$ sudo service apache2 stop  
$ sudo service gitlab stop  

// perform the modification that fixes it, if you indeed configured Gitlab to be accessed with a custom context path  
$ sudo -u git -H nano ~git/gitlab-shell/config.yml  

# Url to gitlab instance. Used for api calls. Should end with a slash.
-gitlab_url: "http://localhost/"
+gitlab_url: "http://localhost/<my_context_path>/"

// restart services  
$ sudo service gitlab start  
$ sudo service apache2 start  

// Try to push again from your particular Gitlab user local repository, to the Gitlab remote repository    
$ cd <path_to_my_local_repository>  
$ sudo -u <OS_username_that_owns_the_local_repository> -H git push -u origin master  
Counting objects: 3202, done.  
Delta compression using up to 2 threads.  
Compressing objects: 100% (3115/3115), done.  
Writing objects: 100% (3202/3202), 11.56 MiB | 5.34 MiB/s, done.  
Total 3202 (delta 609), reused 0 (delta 0)  
To `git@<my_FQDN>:<my_Gitlab_user_or_group_name>/<my_gitlab_project_ID>.git`  
  * [new branch]      master -> master  
Branch master set up to track remote branch master from origin.  
$   

关于 "类似于stackoverflow.com/questions/13071234/… – Paul Verest Jul 18 at 6:20" (无法推送到新的gitlab安装):
不,这个页面主题中的问题并不相同。


0
在我的情况下,原因是nginx强制重定向到https。运行以下命令检查git用户是否可以使用gitlab-api:
sudo -u git -H /home/git/gitlab-shell/bin/check

在服务器上。在我的案例中,输出结果为

Check GitLab API access: FAILED. code: 301

我必须更改/home/git/gitlab-shell/config.yml中的gitlab_urlhttps://<domain>


0

对我来说,这是因为我在/etc/ssh/sshd_config中限制了谁可以通过SSH访问我的服务器,允许用户git。


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