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

Git远程仓库提示'detected dubious ownership'问题求助

排查步骤

1. 确认本地safe.directory配置是否生效

  • 执行以下命令查看全局配置中的安全目录列表:
    git config --global --get-regexp safe.directory
    
    确认/var/git/repo_name是否在列表中,注意路径必须完全匹配(包括大小写、绝对路径格式)。
  • 如果全局配置无效,尝试在本地克隆仓库中添加仓库级配置:
    cd ~/dev/repo_name
    git config --add safe.directory /var/git/repo_name
    

2. 细查远程仓库的权限细节

  • 检查远程仓库根目录的权限位:
    ssh your_git_user@remote_host "ls -ld /var/git/repo_name"
    
    确保权限为750或770(组用户需拥有读/执行权限)。
  • 检查.git目录及内部文件的权限:
    ssh your_git_user@remote_host "ls -ld /var/git/repo_name/.git && ls -l /var/git/repo_name/.git | head -10"
    
    确认.git目录及核心文件(如config、HEAD)的组权限为可读。
  • 验证当前Git用户是否真的在git users组内:
    ssh your_git_user@remote_host "id -nG"
    
    输出中必须包含git users。

3. 排查Git版本与共享仓库配置

  • 分别查看本地和远程的Git版本:
    # 本地
    git --version
    # 远程
    ssh your_git_user@remote_host "git --version"
    
    该报错是Git 2.35.0+的安全特性,若版本差异过大可能引发兼容问题。
  • 检查远程仓库的共享配置:
    ssh your_git_user@remote_host "cd /var/git/repo_name && git config core.sharedRepository"
    
    若未设置值,执行以下命令开启组共享:
    ssh your_git_user@remote_host "cd /var/git/repo_name && git config core.sharedRepository group"
    

4. 验证SSH连接的身份一致性

  • 测试SSH登录时的用户组信息,确认与Git连接用户一致:
    ssh your_git_user@remote_host "id -un && id -nG"
    
  • 检查本地~/.ssh/config,确认针对该远程主机的用户配置是否正确,避免使用了错误的SSH身份。

5. 检查文件系统ACL规则

  • 查看远程仓库目录的ACL配置,排查是否存在额外权限限制:
    ssh your_git_user@remote_host "getfacl /var/git/repo_name"
    
    若存在拒绝当前用户/组访问的规则,需使用setfacl命令调整。

6. 远程本地直接测试定位问题

  • 在远程服务器上切换到仓库目录,直接执行Git命令:
    ssh your_git_user@remote_host "cd /var/git/repo_name && git status"
    
    如果远程本地执行也报可疑所有权错误,说明问题出在远程的Git配置或系统权限;若正常,则问题在本地到远程的连接逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 02:40:14