Git Remote:错误:致命:协议错误:行长度错误字符:Unab

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

Git Remote: Error: fatal: protocol error: bad line length character: Unab

gitsshauthorized-keys

提问by user437899

I set up a git server and want now to push initially my repo from the client. I used git push origin masterand get this error message:

我设置了一个 git 服务器,现在想从客户端最初推送我的 repo。我使用git push origin master并收到此错误消息:

fatal: protocol error: bad line length character: Unab

I don't know what's wrong. I don't know what "Unab" is. I tried to resize the shell but it is still "Unab". I cannot find a solution for this error message.

我不知道怎么了。我不知道“Unab”是什么。我试图调整外壳的大小,但它仍然是“Unab”。我找不到此错误消息的解决方案。

I setup the server with "authorized_keys" and SSH. (I can connect to it, using SSH.)

我使用“authorized_keys”和 SSH 设置了服务器。(我可以使用 SSH 连接到它。)

It seems to be a git problem?

这似乎是一个git问题?

BTW: The server is set up in a Windows 7 VM

顺便说一句:服务器设置在 Windows 7 VM 中

回答by Edward Thomson

This error message is a bit obtuse, but what it's actually trying to tell you is that the remote server didn't reply with a proper git response. Ultimately, there was a problem on the server running the git-receive-packprocess.

这个错误消息有点迟钝,但它实际上试图告诉你的是远程服务器没有用正确的 git 响应进行回复。最终,运行该git-receive-pack进程的服务器出现问题。

In the Git protocol, the first four bytes should be the line length. Instead, they were the characters Unab... which is probably the beginning an error message of some kind. (ie, it's probably "Unable to..." do something).

在 Git 协议中,前四个字节应该是行长。相反,它们是字符Unab......这可能是某种错误消息的开始。(即,它可能是“ Unable to...”做某事)。

What happens when you run ssh <host> git-receive-pack <path-to-git-repository>? You should see the error message that your git client is barfing on and you may be able to correct it.

跑步时会发生什么ssh <host> git-receive-pack <path-to-git-repository>?您应该会看到 git 客户端发出的错误消息,并且您可以更正它。

回答by janos

I had similar issue, but the exact error message was:

我有类似的问题,但确切的错误信息是:

fatal: protocol error: bad line length character: Usin

致命:协议错误:坏行长度字符:Usin

This is in Windows, with GIT_SSHset to the path of plink.exeof PuTTY.

这是在Windows中,GIT_SSH设置为plink.exePuTTY的路径。

Possible problems and solutions:

可能出现的问题及解决方法:

  • Make sure the path to plink.exeis correct. Unix style path works fine too, for example /c/work/tools/PuTTY/plink.exe
  • Make sure the key agent of PuTTY (pageant.exe) is running
  • Make sure the key agent contains a valid key to access the server
  • 确保路径plink.exe正确。例如,Unix 风格的路径也能正常工作/c/work/tools/PuTTY/plink.exe
  • 确保 PuTTY ( pageant.exe)的关键代理正在运行
  • 确保密钥代理包含访问服务器的有效密钥

回答by Amit Shah

For GitExtension users:

对于 GitExtension 用户:

I faced the same issue after upgrading git to 2.19.0

将 git 升级到 2.19.0 后我遇到了同样的问题

Solution:

解决方案:

Tools > Settings > Git Extensions > SSH

工具 > 设置 > Git 扩展 > SSH

Select [OpenSSH] instead of [PuTTY]

选择 [ OpenSSH] 而不是 [ PuTTY]

enter image description here

在此处输入图片说明

回答by MaeseDude

I had the same kind of problem after installing GIT on Windows. At first it worked; then, a day later (after a PC reboot), it didn't anymore, and I got this:

在 Windows 上安装 GIT 后,我遇到了同样的问题。起初它起作用了;然后,一天后(在 PC 重新启动后),它不再存在,我得到了这个:

$ git pull
fatal: protocol error: bad line length character: git@

The problem was that after the reboot, the automatically started Putty "pageant.exe" didn't have the private key active anymore. When you add a key in pageant, it's not a persistent setting by default. I just had to add the key again, and it worked fine. So, for that case, it's necessary to make pagenant load the key automatically, as discussed here:

问题是在重新启动后,自动启动的 Putty “pageant.exe” 不再有私钥处于活动状态。在选美中添加密钥时,默认情况下它不是持久设置。我只需要再次添加密钥,它工作正常。因此,对于这种情况,有必要让 pagenant 自动加载密钥,如下所述:

https://www.digitalocean.com/community/tutorials/how-to-use-pageant-to-streamline-ssh-key-authentication-with-putty

https://www.digitalocean.com/community/tutorials/how-to-use-pageant-to-streamline-ssh-key-authentication-with-putty

回答by Christer Fernstrom

Maybe you have a statement in the server's .bashrc that produces output. I, for example had this:

也许您在服务器的 .bashrc 中有一条生成输出的语句。例如,我有这个:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
rvm use ruby-1.9.3-p194@rails32

In this case the output from the rvm use will be (wrongly) interpreted as coming from git. So replace it by:

在这种情况下,rvm 使用的输出将(错误地)解释为来自 git。所以将其替换为:

rvm use ruby-1.9.3-p194@rails32 > /dev/null

回答by Stanley Emmanuel

After loading the SSH private key in Git Extensions, this issue gets resolved.

在 Git Extensions 中加载 SSH 私钥后,此问题得到解决。

回答by Stanley Emmanuel

You can redirect any output from .bashrcto stderr:

您可以将任何输出重定向.bashrcstderr

# inside .bashrc
echo 'some error/warning/remind message' 1>&2

git will ignore this symbols

git 会忽略这个符号

回答by syclee

I had a similar problem on Windows using Git Bash. I kept getting this error when trying to do a git clone. The repository was on a Linux box with GitLab installed.

我在使用 Git Bash 的 Windows 上遇到了类似的问题。尝试执行 git clone 时,我不断收到此错误。该存储库位于安装了 GitLab 的 Linux 机器上。

git clone git@servername:path/to/repo
fatal: protocol error: bad line length character: git@

I made sure the ssh key was generated. The public key was added on GitLab. The ssh-agent was running and the generated key was added (github link).

我确保生成了 ssh 密钥。公钥已添加到 GitLab 上。ssh-agent 正在运行并添加了生成的密钥(github 链接)。

I ran out of options and then finally tried closing Git Bash and opening it again by right clicking 'Run as Administrator'. Worked after that.

我用完了选项,然后最后尝试关闭 Git Bash 并通过右键单击“以管理员身份运行”再次打开它。在那之后工作了。

回答by acveer

This might help someone. When I was trying to clone a project from an EC2 instance, I was getting the below error:

这可能会帮助某人。当我尝试从 EC2 实例克隆项目时,出现以下错误:

Cloning into 'repo1'...
fatal: protocol error: bad line length character: logi

The resolution for me includes the below steps:

我的解决方案包括以下步骤:

  1. Ensure SSH key (public) is added/updated in the EC2 instance.
  2. Ensure authentication agent (in my case its Pageant=Putty Authentication Agent) is running and the corresponding private key is loaded.
  3. Use the EC2 SSH key ID for the public key for git clone. Example:

    git clone ssh://{SSH Key ID}@someaccount.amazonaws.com/v1/repos/repo1

  1. 确保在 EC2 实例中添加/更新了 SSH 密钥(公共)。
  2. 确保身份验证代理(在我的例子中是它的 Pageant=Putty 身份验证代理)正在运行并加载了相应的私钥。
  3. 使用 EC2 SSH 密钥 ID 作为 git clone 的公钥。例子:

    git clone ssh://{SSH 密钥 ID}@someaccount.amazonaws.com/v1/repos/repo1

回答by Thu 01 Jan 1970 000000 GMT

For me it was becuase I recently added

对我来说是因为我最近添加了

RequestTTY force

into .ssh/config

进入.ssh/config

commenting this out allowed it to work

对此进行评论可以使其正常工作