【问题标题】:Git push error: remote: error: insufficient permission for adding an object to repository database ./objectsGit推送错误:远程:错误:将对象添加到存储库数据库./objects的权限不足
【发布时间】:2017-04-05 14:00:53
【问题描述】:

多年来,我一直在努力在 Redhat 上的 apache 下设置 Git。

  • Apache 版本:erver 版本:Apache/2.4.6 (Red Hat Enterprise Linux)
  • Git 版本 1.8.3.1
  • Red Hat Enterprise Linux Server 7.1 Beta 版
  • apache下的Git配置:
<VirtualHost *:80>
        SetEnv GIT_PROJECT_ROOT /var/www/git
        SetEnv GIT_HTTP_EXPORT_ALL
        ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

<Directory "/usr/libexec/git-core*">
   Options ExecCGI Indexes
   Order allow,deny
   Allow from all
   Require all granted
</Directory>

<LocationMatch "^/git/.*/git-receive-pack$">
    AuthType Basic
    AuthName "Git Access"
    AuthUserFile /var/www/passwd.git
    Require valid-user
</LocationMatch>
</VirtualHost>
  • 在我做的服务器站点上
mkdir  /var/www/test1
cd /var/www/git/test1

# init repo
git init --bare
touch git-daemon-export-ok
cp hooks/post-update.sample hooks/post-update
git config http.receivepack true
git config core.sharedRepository group
git update-server-info

chown -R apache:apache .
chmod -R 775 .
  • 服务器上的 Git 配置文件如下
[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        sharedRepository = group
[http]
        receivepack = true

在我将裸服务存储库 /var/www/git/test1 克隆为之后

git 克隆http://192.168.26.129/git/test1

当我从客户端推送任何更改时,我仍然收到错误

$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 202 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
Username for 'http://192.168.26.129': briangit
remote: error: insufficient permission for adding an object to repository database ./objects
remote: fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To http://192.168.26.129/git/test1
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'http://192.168.26.129/git/test1'

我在网上做了很多研究,并尽了一切可能的尝试。 我真的不知道问题是什么。请帮忙。

【问题讨论】:

  • 它是裸(空)回购吗?

标签: git apache


【解决方案1】:

建议您检查文件权限。

检查ssh key的文件权限,可以用chmod修改。 您更改了整个目录的权限,我同意 Splash 是一个坏主意。

如果你能记住目录的原始权限是什么,我会尝试将它们设置回那个,然后执行以下操作

cd ~/.ssh
chmod 700 id_rsa

chmod 400 ~/.ssh/id_rsa

chmod 777 ~/.ssh/id_rsa

CHMOD 权限:

#   Permission  rwx
7   read, write and execute rwx
6   read and write  rw-
5   read and execute    r-x
4   read only   r--
3   write and execute   -wx
2   write only  -w-
1   execute only    --x
0   none    ---

在哪里可以找到密钥?

.ssh 文件夹。这会将 id_rsa 文件设置为 rwx(读取、写入、执行),仅供所有者(您)使用,其他所有人的访问权限为零。

如果以上都没有帮助,请尝试查看您的小组。将用户添加到组并尝试将您的分支推送到远程源/主。

【讨论】:

  • 好吧,你只是使用不同的协议,即 http.. 这不是问题所在。我遇到http的唯一问题是不可能签入大小为4gb的文件。我更喜欢使用 ssh。那么它值得一试。您已更改文件的所有者和权限。
  • 谢谢,我使用智能 http 而不是 ssh 的 git,不确定 http 与 rsa 有什么关系。服务器上存储库的所有者“apache”和客户端“briangit”在同一个“apache”组中。
  • 也许检查用户是否已添加到组中,以便他/她可以将分支拉或推到远程?
  • 我的存储库是空的裸存储库。文件大小应该没有问题。
  • 与大小无关。这就是我评论这个裸仓库的原因,这就是你遇到这个问题的原因。您只需要检查作为您机器的客户端中 ssh 密钥的权限并检查用户组。你试过上面提到的命令吗?
【解决方案2】:

注意:我已经有 10 多年没有接触过 Apache 了,所以可以根据需要多加盐。但是,有一个明显的问题:

chmod -R 755 .

(完全)不要那样做。你不应该这样做。而不是:

git init --bare
git config core.sharedRepository group

使用单行序列:

git init --bare --shared=group

(或只是--shared,意思相同)。

我不清楚您何时以及为什么要将http.receivepack 配置为true,但请参阅Documentation/git-http-backend.txt

【讨论】:

  • 感谢 Torek,事实证明 SELinux 是这个错误的罪魁祸首。禁用后,它工作正常。
  • 啊,SELinux。我自己从来没有让 Git 服务器在它下面工作。
  • @briantalk 如果你把它写到你的 OP 会很有用,所以这个有用的信息不会隐藏在评论中。虽然对我来说它并没有解决我的问题。
猜你喜欢
  • 1970-01-01
  • 2012-07-08
  • 2021-04-23
  • 1970-01-01
  • 2012-10-15
  • 1970-01-01
  • 2010-12-27
  • 2012-08-11
  • 1970-01-01
相关资源
最近更新 更多