Centos搭建GIT私服
安装git
Centos默认自带Git
可以通过以下命令进行查看
git --version
默认是1.8
创建用户
groupadd git
adduser git -g git
password git
先创建一个用户组
再在这个用户组里面创建一个用户
再给用户设置密码
创建authorized_keys文件
cd /home/git
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
cd /home
chown -R git:git git
要注意的是文件权限和所属用户。
(后续的git clone如果需要密码,很有可能是git用户没有访问authorized_keys文件的权限)
客户端创建密钥并上传
ssh-keygen -t rsa -C "your_email"
该命令会产生两个文件: id_rsa对应私钥,id_rsa.pub对应公钥。
将id_rsa.pub中的内容写到服务器的authorized_keys文件中。
如果有多个客户端,那么在authorized_keys文件中,一行保存一个客户端的公钥。
创建git仓库
为了方便管理,所有的git仓库都置于同一目录下,假设为/home/gitrepo,
cd /home
mkdir gitrepo
chown git:git gitrepo
接下来创建git仓库:test.git
cd gitrepo
git init --bare test.git
把仓库所属用户改为git
chown -R git:git test.git
注意每次新建的仓库,都要修改仓库的所属用户
git私服搭建完毕
push 和 clone示例
打开git bash
git clone git@ip:/home/gitrepo/test.git
git remote add origin git@ip:/home/gitrepo/test.git
git push -u origin
原文章地址https://www.cnblogs.com/gattaca/p/6252416.html