下面按常见场景给你讲一下「Linux 上 GitLab 的远程配置」,分为 GitLab 服务端(远程服务器) 和 本地客户端连接远程 GitLab 两部分。
sudo apt update
sudo apt install -y curl openssh-server ca-certificates postfix
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ce
如果是公网服务器,
EXTERNAL_URL写成你的域名或 IP
sudo gitlab-ctl reconfigure
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 22
浏览器访问:
http://服务器IP
sudo vim /etc/gitlab/gitlab.rb
常见配置:
external_url 'http://gitlab.example.com'
gitlab_rails['gitlab_ssh_host'] = '192.168.1.100'
gitlab_rails['gitlab_shell_ssh_port'] = 22
修改后:
sudo gitlab-ctl reconfigure
sudo apt install git
git config --global user.name "yourname"
git config --global user.email "you@example.com"
ssh-keygen -t ed25519 -C "you@example.com"
cat ~/.ssh/id_ed25519.pub
把公钥复制到:
GitLab → User → Settings → SSH Keys
git clone git@gitlab.example.com:group/project.git
或 HTTPS:
git clone https://gitlab.example.com/group/project.git
git add .
git commit -m "init"
git push origin main
22 端口开放ssh -T git@gitlab.example.com
vim ~/.ssh/config
Host gitlab.example.com
Port 2222
sudo gitlab-rake "gitlab:password:reset[root]"
我可以更针对性地讲:
你可以直接说你的 Linux 发行版 + 使用场景。