Git推送导致致命:协议错误:线路长度不好:这个

时间:2014-03-11 00:45:36

标签: git ssh repository gitlab

我正在尝试让GitLab在我的服务器上运行(运行CentOS 6.5)。我跟着gitlab-receipe到了线,但我无法让它工作。我能够访问Web界面,创建新项目,但推送到主分支返回以下错误:

fatal: protocol error: bad line length character: This

我已经对生产环境进行了检查,结果如下:

Checking Environment ...

Git configured for git user? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version >= 1.7.9 ? ... OK (1.8.0)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ... 
ASC / Wiki ... repository is empty
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files: 
    /home/git/repositories: OK
    /home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli 2.4.10
Send ping to redis server: PONG
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... no
  Try fixing it:
  Redownload the init script
  For more information see:
  doc/install/installation.md in section "Install Init Script"
  Please fix the error above and rerun the checks.
projects have namespace: ... 
ASC / Wiki ... yes
Projects have satellites? ... 
ASC / Wiki ... can't create, repository is empty
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/bin/git"
Git version >= 1.7.10 ? ... yes (1.8.3)

Checking GitLab ... Finished

对于init脚本错误,收据显示

  

如果您确定已下载,请不要介意该错误   最新的

因为我已经下载了最新版本,所以我无法真正做到这一点。

过去一周我一直在敲打我的脑袋,无法弄清楚为什么会出现这种错误,任何帮助都会受到赞赏!!

21 个答案:

答案 0 :(得分:35)

如果其他人遇到此问题,解决方法是将用户'git'(或任何用户调用的)的登录shell更改为/bin/bash。这可以通过以下命令完成:usermod -s /bin/bash gitLink)。更改登录shell的原因是因为git用户的默认shell是/sbin/nologin(或者类似,取决于环境),这会阻止git应用程序以git服务器上的git用户身份登录。

答案 1 :(得分:20)

仅供其他用户参考:

fatal: protocol error: bad line length character: no s
can be a truncated answer for "No such project".

在我的情况下,可以通过在gitlab中将用户(甚至是你自己)添加到项目来修复这种错误:

https://gitlab.com/username/your_project/project_members

另外,请确保在您的用户Profile settings > SSH Key or in Project > Settings > Deploy Keys

中设置了您的公开密钥

https://gitlab.com/profile/keys

答案 2 :(得分:12)

要检查的另一件事是.bashrc不会打印额外的东西。 例如' echo" hello"'在.bashrc中创建错误:

kruus@borg:~/malt$ ssh snake01
Last login: Tue Oct 21 10:44:31 2014 from 138.15.166.103
hello
...
kruus@snake01:/net/snake01/usr/hydra/kruus/malt$ git pull
fatal: protocol error: bad line length character: hell

请注意如何打招呼引起一个问题。

删除' echo"你好"'从我的.bashrc允许git再次按预期工作。您可能需要">&的/ dev / null的"如果.bashrc执行更复杂的操作,则删除输出。

答案 3 :(得分:4)

另一种可能性是您拼错了存储库名称。

我在最近两天做了两次。我添加了一个遥控器并拼错了它,我在GitLab上创建项目时拼错了名字。

在我尝试推送到遥控器的两种情况下,我都得到了

fatal: protocol error: bad line length character: No s

请检查拼写!

此外,如果您使用其他名称(如组)创建项目,请确保您添加的遥控器。

答案 4 :(得分:4)

我的问题的解决方案是,我忘记为项目添加部署密钥(对于我尝试部署的用户)。

https://gitlab/group/project/deploy_keys中添加部署密钥将我排除在外。

答案 5 :(得分:4)

您可以通过执行以下操作获取实际的错误消息:

ssh git@yourgitlabserver.com "git-upload-pack yournamespace/yourreponame.git"

根据this git documentation git协议,在每行的开头预期它的大小,然后是内容。看起来GitLab没有这样做并直接发送错误消息。

答案 6 :(得分:2)

sudo gitlab-ctl reconfigure

然后

sudo gitlab-ctl restart

应该做的伎俩

答案 7 :(得分:2)

我今天遇到了这个错误消息("没有"),它实际上与我无权推送到目标存储库有关。即使错误消息非常奇怪,这可能会帮助人们继续工作。

我们使用Gitlab。

答案 8 :(得分:1)

在我的情况下(私钥超过〜/ .ssh / config)我不得不遗漏ssh部分:

git clone ssh://git@hostname:username/repository.git

它适用于:

git clone git@hostname:username/repository.git

错误消息是:

  

致命:协议错误:行长字符错误:没有s

答案 9 :(得分:1)

在我的情况下,我的用户名已更改,此存储库的git配置未更新以匹配新名称。

检查你的git遥控器,确保它们指向正确的位置:

git remote -v

通过手动编辑配置来更新配置:

vim .git/config

或通过命令

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

答案 10 :(得分:0)

另一个...

我的配置有点复杂。在服务器端,我使用名为 Gogs 的自托管 Git 平台(主要是因为它是用 Go 编写的,我 ❤️ Go!)。 Gogs 有一个用于更新的内置 SSH 服务器,但它仍然需要来自主 SSH 服务器(充当某种代理或前端)的一些“帮助”,通常与 Gogs 在同一用户下运行(通常是 { {1}},但这取决于系统管理员)。

最近,我一直在尝试通过 shell 帐户限制访问,在大多数情况下为他们提供 SFTP 访问权限;我也将剩下的几个 FTP 帐户(哎呀!)也移到了 SFTP。这样做时,我终于设法找到了 SSHD 配置上的错误,这使我的设置无法更加自动化(基本上,将用户添加到 SFTP 组或 SSH 组以授予他们访问权限;我不得不重新加载 SSHD每次我添加另一个用户时,这很痛苦……尤其是如果出现了一些错误并且我将失去对远程服务器的 SSH 访问权限!!)。在所有这些更改之后,我确实测试了相当多的帐户,看到它们正在工作,但没有注意到一个微小的错误:用户 git两个组中(SFTP SSH)。由于 SSHD 的配置方式,它将首先查找 SFTP 组,然后查找 SSH。由于该用户两者,SSHD 将只授予其 SFTP 访问权限(这与分配给用户的任何 shell 无关)。所以,发生的事情是回显了以下错误消息:

git

请注意,第一行(以及最后一行)很可能是来自控制台会话管理器的“本地”消息。 PTY allocation request failed on channel 0 This service allows sftp connections only. Connection to my.server.name closed. 收到的错误当然是此服务仅允许 sftp 连接。,因此它得到前四个字母 — This — 提示错误。

确保 git 用户仅在 shell-access 组中解决了问题:

git

这是使用 Gogs 时的预期行为:尽管从 系统 的角度来看,它“允许”shell 帐户(这是让它工作的唯一方法),但这些连接正在被捕获由 Gogs 提供,它知道它不应该允许任何 shell 帐户——SSH 协议仅用于允许 Git 推/拉并使用自己的身份验证(在 Gogs 内部管理——而不是在操作系统级别).

我知道,这很可能是一个边缘情况,影响了 0.000000000000001% 通过 Google 重定向到此答案的人 ?

我的观点很简单:臭名昭著的 PTY allocation request failed on channel 0 Hi there, You've successfully authenticated, but Gogs does not provide shell access. If this is unexpected, please log in with password and setup Gogs under another user. 可能来自 fatal: protocol error: bad line length character: This 行,这意味着您拥有的用户无权访问完整的 shell 帐户。这至少应该给你一个关于开始搜索什么的提示——Git 用户的配置错误,无论是在 SSHD 级别还是在用户 ID/组级别。

答案 11 :(得分:0)

我在Windows上的解决方案是在.git / config中将连接切换到SSH:

[远程“来源”]     url = git@github.com:

如此处所述:

https://help.github.com/en/articles/changing-a-remotes-url

答案 12 :(得分:0)

就我而言,我仅在Windows的“ SSH扩展”中观察到此错误。

同一命令从命令行运行。我将SSH设置从PuTTY切换为OpenSSH,它停止生成错误。

答案 13 :(得分:0)

对于我来说,该错误是通过使用git-shell将远程git-user shell更改为chsh来解决的:

chsh -s $(command -v git-shell) git

官方git-shell documentation。出于安全原因,强烈建议在远程存储库服务器上将此外壳用于git-user。

答案 14 :(得分:0)

有同样的问题,在我的情况下原始回购已被移动,改变.git / config解决了我的问题。

答案 15 :(得分:0)

我的解决方案是取消设置指向putty的GIT_SSH env变量(plink.exe)

答案 16 :(得分:0)

在我的情况下,只需向其他人添加可能的解决方案。 在我的情况下,我试图推动标签。

git push heroku MYTAG:master

直到我取消引用它标记的工作

才开始
git push heroku MYTAG^{}:master

您可以在此处详细了解: What does ^{} mean in git?

  

<rev>^{}, e.g. v0.99.8^{}

     

后缀为^后跟空括号对意味着该对象可以是标记,并递归取消引用该标记,直到找到非标记对象。

答案 17 :(得分:0)

更改git的shell

usermod -s /usr/bin/git-shell git

答案 18 :(得分:0)

我的错误是:fatal: protocol error: bad line length character: No s

这是因为我忘了在我的Maven项目的pom.xml中指定SCM标记,所以它使用了来自父项目的SCM信息。 我还必须将我们的Jenkins用户添加到GitLab中的项目中。

答案 19 :(得分:0)

我有同样的问题,结果发现我正在开发一个git分支。我需要做的就是向主人推进。

$ git push <remote> <local branch name>:<remote branch to push into>

答案 20 :(得分:0)

将我的经验添加到这长长的可能解决方案列表中。

在我的情况下,我可以访问我克隆的repo,但无法访问package.json所指的其他内部存储库作为依赖项或devDependencies。 所以解决方案也是可以访问这些回购。