Ubuntu下GitLab权限问题排查与修复
一 常见症状与定位
二 SSH 访问权限修复
ssh-keygen -t rsa -b 2048 -C "your_email@example.com",默认生成 ~/.ssh/id_rsa 与 ~/.ssh/id_rsa.pub。cat ~/.ssh/id_rsa.pub 的内容,在 GitLab 右上角头像 → Preferences → SSH Keys 中粘贴并保存。chmod 600 ~/.ssh/id_rsa;必要时启动 ssh-agent 并添加私钥:eval "$(ssh-agent -s)" 与 ssh-add ~/.ssh/id_rsa。Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa
ssh -T git@gitlab.com,成功会显示欢迎信息。若曾连接失败,可清理旧缓存:ssh-keygen -R gitlab.com。三 HTTPS 访问与凭据问题
git clone https://<token>@gitlab.example.com/namespace/project.gitgit config --global credential.helper store(明文保存)或 git config --global credential.helper cache(内存缓存)。四 项目与组成员权限配置
五 服务器与系统层面权限修复
sudo chown -R git:git /var/opt/gitlab
sudo chmod -R 755 /var/opt/gitlab
sudo gitlab-ctl reconfigure,必要时重启:sudo gitlab-ctl restart。sudo gitlab-ctl status、sudo gitlab-ctl tail;执行自检:sudo gitlab-rake gitlab:check SANITIZE=true --trace。sudo ufw allow 80/tcp 与 sudo ufw allow 443/tcp;如使用自托管实例的 SSH,还需放行 22/tcp。