您的位置:首页 > 编程语言

git on server(ssh)深入剖析,github提供服务原理

2016-07-19 14:00 453 查看
1.安装好linux,安装好git(192.168.1.239)

2.创建一个用户zph(让此用户提供git on server),密码设置为12345678

[python]
view plain
copy





# useradd zph  

[python]
view plain
copy





# passwd zph  

3.切换到zph用户

[python]
view plain
copy





# su zph  

[python]
view plain
copy





$ cd  

4.创建一个远程仓库

[python]
view plain
copy





$ git init --bare sample.git  

5.在windows下(192.168.1.5),打开git bash

[python]
view plain
copy





$ git clone zph@192.168.1.239:/home/zph/sample.git  

终端会让输入密码,此时输入zph用户的密码即(12345678)6.为了让用户,不用每次都输入密码,在linux生成.ssh目录

[python]
view plain
copy





$ ssh-keygen -t rsa -C "youremail@example.com"  

7.进入.ssh,新建一个authorized_keys文件

[python]
view plain
copy





$ cd /home/zph/.ssh/  

[python]
view plain
copy





$ vi authorized_keys  

8.打开windows中当前用户的.ssh/id_rsa.pub,复制里面的内容,粘贴到第7步中的authorized_keys中
9.更改authorized_keys文件的权限

[python]
view plain
copy





$chmod 600 authorized_keys  

10.验证authorized_keys有没有生效,打开windows

[python]
view plain
copy





$ ssh zph@192.168.1.239  

如果不需要输入密码,代表生效了
11.重复第5步,已经不需要输入密码了

12.代码自动更新

cp /home/zph/sample.git/hooks/update.sample /home/zph/sample.git/hooks/update

13.打开update,先清空内容,然后进行编辑如下

cd
/usr/share/nginx/html/sample

unset GIT_DIR

git
checkout master

git pull
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  github git ssh