You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git私有服务器推送失败:Permission Denied错误排查求助

Git Push Permission Denied: Fixes Beyond Basic File Permissions

You’ve already tried tweaking file and directory permissions (even setting them to 777!) and still hit this frustrating error when pushing to your private Git server:

remote: fatal: Unable to create temporary file '/var/dev/xsl/hub/.git/./objects/pack/tmp_pack_XXXXXX': Permission denied
error: remote unpack failed: index-pack abnormal exit
To own_server:/var/dev/xsl/hub
! [remote rejected] current -> current (unpacker error)
error: failed to push some refs to 'marcin@own_server:/var/dev/xsl/hub'

Let’s break down the less obvious causes and step-by-step fixes for this issue— I’ve troubleshooted similar problems countless times:

1. SELinux or AppArmor Blocking Git Operations

Most modern Linux distributions run security modules like SELinux (RHEL/CentOS) or AppArmor (Ubuntu/Debian) that enforce access rules independently of file permissions. Even with 777 permissions, these modules can block Git from creating temporary pack files in your repository.

Fix:

  • Test temporarily: Disable SELinux with sudo setenforce 0 (or stop AppArmor with sudo systemctl stop apparmor) and try pushing again. If it works, the security module was the culprit.
  • Permanent SELinux fix:
    1. Label your repository directory with the correct SELinux context:
      sudo semanage fcontext -a -t git_system_content_t "/var/dev/xsl/hub(/.*)?"
      
    2. Apply the context to existing files:
      sudo restorecon -Rv /var/dev/xsl/hub
      
  • Permanent AppArmor fix:
    Edit the Git profile (usually /etc/apparmor.d/usr.bin.git) to add allow rules for your repository path, then reload AppArmor with sudo systemctl reload apparmor.

2. Misconfigured core.sharedRepository Git Setting

Git has its own internal permission system for shared repositories. If this setting isn’t tuned correctly, even proper directory permissions won’t let users create pack files during pushes.

Fix:

  1. On your Git server, navigate to the repository root:
    cd /var/dev/xsl/hub
    
  2. Set the shared mode (use group if your users share a common group, or all for full open access):
    git config core.sharedRepository group
    
  3. Sync the repository’s ownership and permissions with your user group (replace dev-team with your actual group):
    sudo chown -R :dev-team /var/dev/xsl/hub
    sudo chmod -R g+w /var/dev/xsl/hub
    

3. Missing Execute Permissions on Parent Directories

You can’t access a directory even if it has full permissions if any parent directory in the path lacks execute (x) permission for your user. For example, if /var/dev/xsl is locked down, marcin can’t reach the hub repository inside it.

Fix:

Check permissions for every directory in the path:

ls -ld /var /var/dev /var/dev/xsl /var/dev/xsl/hub

Ensure the marcin user (or their group) has the execute permission for each directory. Fix missing permissions with:

sudo chmod o+x /var/dev/xsl  # Example: add execute access for other users

4. Disk Space or Inode Exhaustion

Sometimes "Permission denied" is a red herring—your server might be out of disk space or inodes (file system entries). When the system can’t create new files, it often returns permission errors instead of the actual issue.

Fix:

  • Check available disk space:
    df -h
    
  • Check inode usage (file entries):
    df -i
    

If either is full, clean up log files, old backups, or expand your server’s storage.

5. Git Shell Restrictions (If Using git-shell)

If you’ve set up git-shell as the login shell for Git users to restrict access, it might be blocking push operations accidentally.

Fix:

  • Verify git-shell is listed in /etc/shells (add it with echo "/usr/bin/git-shell" | sudo tee -a /etc/shells if missing).
  • Ensure your user’s shell is set correctly:
    sudo chsh -s /usr/bin/git-shell marcin
    
  • Double-check the repository doesn’t have push restrictions like receive.denyCurrentBranch enabled unless intended.

内容的提问来源于stack exchange,提问作者maw2be

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:04:24