CentOS 上 GitLab 权限问题排查与修复指南
一 项目与角色权限设置
二 系统与服务运行权限
chown -R git:git /var/opt/gitlab/git-data/repositorieschmod -R 755 /var/log/gitlabnode_exporter['enable'] = false,随后 gitlab-ctl reconfigure && gitlab-ctl restart。三 SSH 与网络访问控制
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"。firewall-cmd --permanent --add-service=httpfirewall-cmd --permanent --add-service=httpsfirewall-cmd --permanent --add-service=sshfirewall-cmd --reload四 常见报错与快速修复对照表
| 症状 | 可能原因 | 快速修复 |
|---|---|---|
| remote: You are not allowed to push code to this project | 用户角色权限不足(如 Guest/Reporter)或分支受保护 | 在项目 Settings → Members 将用户角色提升到 Developer/Maintainer;必要时在 Settings → Repository → Protected branches 调整保护策略 |
| 502 Bad Gateway 且日志有 statfs() permission denied | 日志或数据目录权限异常,或 node_exporter 触发权限调用失败 | 执行 chmod -R 755 /var/log/gitlab;必要时在 gitlab.rb 中设置 node_exporter['enable'] = false;随后 gitlab-ctl reconfigure && gitlab-ctl restart |
| 页面打不开或端口不通 | 防火墙未放行 80/443/22 或自定义端口 | 使用 firewall-cmd 放行相应服务/端口并 reload |
| 无法克隆/推送(认证失败) | 未添加 SSH 公钥 或使用了错误协议/端口 | 在用户 SSH Keys 添加公钥;确认使用 SSH 地址(如 git@host:group/project.git)或正确 HTTPS 凭据 |