zl程序教程

您现在的位置是:首页 >  系统

当前栏目

Linux搭建Git服务器教程

2023-09-14 09:16:10 时间
1.下载安装 git openssh-server
# sudo apt-get install git openssh-server
# git --version

2.创建 git 账号密码
创建 git 账号
为我们刚刚搭建好的 git 创建一个账号
# useradd -m gituser
然后为这个账号设置密码
# passwd gituser

3.初始化 git 仓库并配置用户权限
创建 git 仓库并初始化
我们创建 /data/repositories 目录用于存放 git 仓库
# mkdir -p /data/repositories
创建好后,初始化这个仓库
# cd /data/repositories/ && git init --bare test.git

4.初始化 git 仓库并配置用户权限
创建 git 仓库并初始化
配置用户权限
给 git 仓库目录设置用户和用户组并设置权限
# chown -R gituser:gituser /data/repositories
# chmod 755 /data/repositories
查找git-shell所在/usr/local/git/bin/目录下
修改/etc/passwd最后一行为:
gituser:x:500:500::/home/gituser:/usr/local/git/bin/git-shell

6.测试搭建好的Git服务
克隆 test repo 到本地
# cd ~ && git clone gituser@119.29.214.137:/data/repositories/test.git
# touch test.txt
# git add .
# git commit -m "first commit"
# git push origin master 
or
# git push origin HEAD:refs/for/master