git daemon over ssh - fatal: protocol error: bad line length character: SSH-

git daemon over ssh - fatal: protocol error: bad line length character: SSH-

我在服务器端创建了用户 "gitproxy",将我的 ssh 密钥添加到其授权密钥中并尝试通过 ssh 使用 git 守护程序:

gitproxy:~$ git daemon --port=2222 --verbose

但出现错误: 在客户端:

o:~/git$ git clone ssh://server>:2222/home/gitproxy/git
Cloning into 'git'...
ssh: connect to host <server> port 2222: Connection refused
fatal: Could not read from remote repository.

在服务器端:

[18666] Ready to rumble
[18667] Connection from 192.168.211.174:42416
fatal: protocol error: bad line length character: SSH-
[18666] [18667] Disconnected (with error)

存储库存在。此外,我通常通过 SSH 进入此服务器而无需密码(因此,我的 ssh 密钥被接受):

$ ssh gitproxy@192.168.201.84
gitproxy@192.168.201.84:~$

此外,我可以从我的桌面(客户端)获取带有 git-receive-pack 的分支列表:

$ ssh gitproxy@192.168.201.84  git-receive-pack  /home/gitproxy/git
008fef8bbf80818e6b634ca56c3ef6c24e5bbdb7bf74 refs/heads/masterreport-status delete-refs side-band-64k quiet atomic ofs-delta agent=git/2.16.1
0046ef8bbf80818e6b634ca56c3ef6c24e5bbdb7bf74 refs/remotes/origin/HEAD
0048ef8bbf80818e6b634ca56c3ef6c24e5bbdb7bf74 refs/remotes/origin/master

我检查了在 Whosebug 上提出的所有可能的修复。但是 git 守护进程仍然 returns 错误。 如果有任何帮助,我将不胜感激。提前致谢!

git-daemon 不讲 SSH 协议,它讲简单的 git 协议;协议的 URL 必须以 git:// 开头,而不是 ssh://。 IE。您服务器的 URL 是 git://192.168.201.84:2222/.

要通过 ssh 使用 git 存储库,您需要一个 ssh 服务器。所以看起来你有一个:在 gitproxy@192.168.201.84;好的,那么回购的 URL 是 ssh://gitproxy@192.168.201.84/home/gitproxy/git。 URL 的另一种 "scp-like" 语法是 gitproxy@192.168.201.84:git.

git 守护进程是一个实现 git 协议的服务器,即与 git://... URL 一起使用的协议。它不理解 SSH 协议,所以当你理解时:

git clone ssh://<server>:2222/home/gitproxy/git

您正在尝试通过 SSH 协议连接到 <server>:2222(由于 ssh://... URL)。然后 git daemon 不理解 SSH 发送给它的内容(错误消息中的 SSH- 是初始 SSH 握手的一部分)。

如果你真的打算使用 SSH 协议与远程存储库交互,根本不需要使用 git daemon。通过使用 ssh://... URL 形式,git 命令将使用 SSH 调用所需的远程命令(例如您手动执行的 receive-pack)。在这种情况下,只需删除 URL 的端口规范并退出服务器上的 git daemon。身份验证和加密由作为传输机制的 SSH 提供,授权使用文件系统权限完成。

如果您真的想使用 git daemongit 协议,请将 URL 改为 git://<server>:2222/...。请注意,git 协议不提供任何身份验证、加密或授权机制,公开的存储库完全 public.

But I need for --access-hook of git daemon (or any other mechanism for executing some actions when I run "git pull" on client side).

然后,仅使用 SSH(根本没有 git 守护程序),您可以使用 SSH forced command mechanism that I illustrate for instance with gitolite.

在 ~gitproxy/.ssh/authorized_keys 中,你可以调用任何你想要的脚本来执行操作,然后 然后 调用 Git 本身,使用 $SSH_ORIGINAL_COMMAND(将包括“git-upload-pack|git-receive-pack|git-upload-archive" Git 命令)。

您甚至可以安装 gitolite 本身,因为它会为您管理授权部分。