【问题标题】:git cannot exec 'pack-objects': Permission deniedgit无法执行'pack-objects':权限被拒绝
【发布时间】:2020-09-21 19:08:19
【问题描述】:

从我刚刚添加的自托管 git 远程拉取时出现此错误。

$ git pull myremote master
fatal: cannot exec 'pack-objects': Permission denied
fatal: git upload-pack: unable to fork git-pack-objects
fatal: The remote end hung up unexpectedly
fatal: protocol error: bad pack header

用引号搜索“cannot exec 'pack-objects': Permission denied”得到的结果为零,所以这不是重复的。关于fatal: protocol error: bad pack header 部分有几个问题,this one 之类的答案建议在.gitconfig 中添加一些内存限制行。这并没有解决我的问题。

根据第一行,我认为某处的某些pack-objects 可执行文件缺少其x 权限。但不是这个:

$ ls -l $(which git-upload-pack)
-rwxr-xr-x 1 root root 1559256 Apr 20 10:20 /usr/bin/git-upload-pack

就上下文而言,远程是运行 Debian 10 的 VPS,而客户端是大约 2003 年运行 Ubuntu 18.04 的古老 Intel Celron 桌面。因此,拉机上的资源限制可能会起作用。

编辑

所有用户都可以执行所有 git 二进制文件:

 $ ls -l /usr/bin/git*
 -rwxr-xr-x 1 root root 2759388 Apr 20 10:20 /usr/bin/git
 lrwxrwxrwx 1 root root       3 Apr 20 10:20 /usr/bin/git-receive-pack -> git
 -rwxr-xr-x 1 root root 1546968 Apr 20 10:20 /usr/bin/git-shell
 lrwxrwxrwx 1 root root       3 Apr 20 10:20 /usr/bin/git-upload-archive -> git
 -rwxr-xr-x 1 root root 1559256 Apr 20 10:20 /usr/bin/git-upload-pack

/usr/bin 在我的路径中:

$ echo $PATH
/home/keith/bin:/home/keith/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

而且我可以在没有 sudo 的情况下运行它们:

$ git-upload-pack
usage: git upload-pack [<options>] <dir>

    --stateless-rpc       quit after a single request/response exchange
    --advertise-refs      exit immediately after initial ref advertisement
    --strict              do not try <directory>/.git/ if <directory> is no Git directory
    --timeout <n>         interrupt transfer after <n> seconds of inactivity

编辑 2

.git 目录似乎也具有正确的权限:

$ ls -la .git{,/objects}
.git:
total 56
drwxr-xr-x  8 keith keith 4096 Sep 21 11:36 .
drwxr-xr-x 22 keith keith 4096 Sep 21 13:09 ..
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 branches
-rw-r--r--  1 keith keith  290 Sep 21 11:36 config
-rw-r--r--  1 keith keith   73 Jul 25  2017 description
-rw-r--r--  1 keith keith    0 Sep 21 12:51 FETCH_HEAD
-rw-r--r--  1 keith keith   23 Jul 25  2017 HEAD
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 hooks
-rw-rw-r--  1 keith keith 1555 Sep 21 10:47 index
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 info
drwxr-xr-x  3 keith keith 4096 Jul 25  2017 logs
drwxr-xr-x 37 keith keith 4096 Jul 25  2017 objects
-rw-rw-r--  1 keith keith   41 Apr  2  2018 ORIG_HEAD
-rw-rw-r--  1 keith keith   46 Sep 21 10:47 packed-refs
drwxr-xr-x  5 keith keith 4096 Jul 25  2017 refs

.git/objects:
total 148
drwxr-xr-x 37 keith keith 4096 Jul 25  2017 .
drwxr-xr-x  8 keith keith 4096 Sep 21 11:36 ..
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 06
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 0a
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 17
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 22
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 29
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 2d
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 30
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 32
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 35
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 3c
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 3f
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 43
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 4f
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 50
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 53
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 5a
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 5f
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 6e
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 72
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 82
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 96
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 a5
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 a8
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 b4
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 b7
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 b9
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 bc
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 c0
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 c3
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 c9
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 cd
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 e7
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 ea
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 info
drwxr-xr-x  2 keith keith 4096 Apr  2  2018 pack

编辑 3

我没有安装 SELinux,所以我不知道除了 linux 权限之外要检查什么上下文。

我看了/usr/lib/git-core。所有文件(可执行文件和符号链接)都是 root 拥有的,但对所有用户都有 rx 权限。最重要的是:

$ ls -lhZ /usr/lib/git-core/{git-upload-pack,git-pack-objects} 
lrwxrwxrwx 1 root root ?    3 Apr 20 10:20 /usr/lib/git-core/git-pack-objects -> git
-rwxr-xr-x 1 root root ? 1.5M Apr 20 10:20 /usr/lib/git-core/git-upload-pack

除了这些:

$ ls -lhZ /usr/lib/git-core/git-sh-*
-rw-r--r-- 1 root root ? 2.3K Apr 20 10:20 /usr/lib/git-core/git-sh-i18n
-rwxr-xr-x 1 root root ? 1.5M Apr 20 10:20 /usr/lib/git-core/git-sh-i18n--envsubst
-rw-r--r-- 1 root root ?  16K Apr 20 10:20 /usr/lib/git-core/git-sh-prompt
-rw-r--r-- 1 root root ? 9.1K Apr 20 10:20 /usr/lib/git-core/git-sh-setup

编辑 4

按照toreksuggestion查看myremote,我在那里登录并检查了相同的嫌疑人:

$ ls -lhZ /usr/bin/git*
-rwxr-xr-x 1 root root ? 2.7M Apr 19 18:19 /usr/bin/git
lrwxrwxrwx 1 root root ?    3 Apr 19 18:19 /usr/bin/git-receive-pack -> git
-rwxr-xr-x 1 root root ? 1.5M Apr 19 18:19 /usr/bin/git-shell
lrwxrwxrwx 1 root root ?    3 Apr 19 18:19 /usr/bin/git-upload-archive -> git
lrwxrwxrwx 1 root root ?    3 Apr 19 18:19 /usr/bin/git-upload-pack ->  

$ ls -lhZ /usr/lib/git-core/{git-upload-pack,git-pack-objects,git}
-rwxr-xr-- 1 root root ? 2.7M Apr 19 18:19 /usr/lib/git-core/git
lrwxrwxrwx 1 root root ?    3 Apr 19 18:19 /usr/lib/git-core/git-pack-objects -> git
lrwxrwxrwx 1 root root ?    3 Apr 19 18:19 /usr/lib/git-core/git-upload-pack -> git

现在我看到了罪魁祸首。

【问题讨论】:

  • 你需要读取和执行git安装中所有文件的权限,并且它们需要可用。
  • 在问题中添加了更多信息以显示 git 二进制读取/可执行权限。
  • 看看其余的 Git 二进制文件,它们通常位于 /usr/lib/git-core 或类似位置。
  • 我不确切知道它是什么,但无论出于何种原因,另一台机器显然无法运行 pack-objects 程序。请记住,获取和推送都依赖于服务器上的一些 other Git;必须正确设置 Git。

标签: git


【解决方案1】:

Edit 4 有最后的线索:问题实际上出在服务器上,由于某种原因,服务器将 /usr/lib/git-core/git 二进制文件设置为模式 754 (rwxr-xr--),而不是模式 755 (rwxr-xr-x)。这意味着任何不是 root 用户且不在组 root 中的人都不允许运行它,并且服务器上该二进制文件的简单 chmod 将解决问题。

【讨论】:

    【解决方案2】:

    您可能想查看您的本地 .git 存储库,尤其是在.git/objects 下。检查文件的所有者和权限,看看 git 是否有权创建它们。

    最有可能发生的情况是,您可能使用sudo 运行过一次git,或者使用su 临时登录为root。只要文件已经存在,就不会成为问题,因为它们将保留其原始权利和所有者,但是如果 Git 必须创建不存在的文件,例如打包对象子目录,如果他这样做 root,之后无法将它们用作您的常规身份是正常的。

    这实际上可能发生在任何命令上,而不仅仅是 Git。因此错误信息,只报告系统给出的错误原因。

    编辑

    考虑到下面的 cmets,您可能还想查看 /usr/libexec/git-core/ 的内容。这包含所有与 git 命令和子命令实际关联的可执行文件。

    其中有git-pack-objects,由git-upload-pack 运营。它们都是不同且不同的可执行文件。

    它仍然没有解释为什么这里会失去权利,但它仍然是一个值得关注的地方。

    祝你好运。

    【讨论】:

    • 这似乎不是问题:.git 中的所有内容都归我所有,而不是 root。我将.git.git/objects目录的权限添加到问题中。
    • 非常感谢您提供此信息补充(以及使用它编辑您的帖子)。您可能还想检查 /usr/libexec/git-core 的内容,其中包含与 Git 子命令匹配的每个二进制文件。此外,git-upload-packgit-pack-objects 是两个不同的可执行文件,后者由前者运行。因此,我将更新我的答案。祝你好运!
    • 我对@9​​87654335@ 和added 中的文件进行了ls -l 处理。没有/usr/libexec 目录。感谢 bk2204 发布正确的目录。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 2018-10-24
    • 2016-04-15
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    相关资源
    最近更新 更多