1、开发者的生成公钥
开发者本地进入~/.ssh中执行ssh-keygen命令,会生成id_rsa(私钥)id_rsa.pub(公钥)。
将id_rsa.pub发送至服务器端。
2、架设GIT服务器。
a.创建git组,添加一个git用户并添加至该组中。
adduser git 创建git用户
passwd git 创建git用户的密码,输入两遍(如果不需密码,可以不设)
su git 切换git用户
cd ~ 进入git的家目录
mkdir .ssh 创建ssh配置目录
cd .ssh
将开发者的公钥内容写入authorized_keys文件,一个一行,多个用户多行。也可将用户的公钥发送至git所在服务器,执行命令写入该文件,如下命令。
cat /home/zhangsan/id_rsa.pub >> /home/git/.ssh/authorized_keys
b.在git目录中创建空的仓库
mkdir project1.git project1是你的项目名称,未来开发者clone时,生成的文件目录名字则为该名
cd project1.git
git --bare init 使用 --bare 会生成一个工作目录的仓库,不会看到代码。
c.出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:
git:x:502:502::/home/git:/bin/bash 改为: git:x:502:502::/home/git:/user/bin/git-shell
3.开发者端
开发者端该有的操作这里就不一一赘述。但要注意的一点是,假如,你的本地服务pull报错或push报错,是服务器端GIT没有配置好,常见报错如下:
bash: git-receive-pack: command not found
fatal: Could not read from remote repository.
以及
bash: git-upload-pack: command not found
fatal: Could not read from remote repository.
解决办法:
需要到服务器端将git-receive-pack和git-upload-pack链接到/usr/bin/中:
ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack