ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
`1.显示服务器版本` ~~~ cat /etc/redhat-release CentOS release 6.4 (Final) ~~~ 服务器IP:172.17.17.37 客户端IP:172.17.17.36 `2.安装git` ~~~ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel ~~~ 下载`git-1.8.2.2.tar.gz` 到 `/usr/local/src` 下载网址[http://code.google.com/p/git-core](http://code.google.com/p/git-core),如果下载不了,可以到[github](https://github.com/git/git/releases/tag/v1.8.2.2)下载 ~~~ cd /usr/local/src tar -zvxf git-1.8.2.2.tar.gz cd git-1.8.2.2 make prefix=/usr/local/git all make prefix=/usr/local/git install ~~~ 增加软连接 ~~~ ln -s /usr/local/git/bin/* /usr/bin/ git --version #如果能显示版本号,即表示成功 ~~~ `3.安装gitosis` ~~~ yum install python python-setuptools cd /usr/local/src git clone git://github.com/res0nat0r/gitosis.git cd gitosis python setup.py install ~~~ 显示`Finished processing dependencies for gitosis==0.2`即表示成功 `4.在客户端上,生成密钥并上传到服务器上` ~~~ ssh-keygen -t rsa #一路回车,不需要设置密码 ~~~ 从开发机客户端,上传刚生成的公钥到服务器(如果修改端口,按步骤4进行配置指定端口) ~~~ scp ~/.ssh/id_rsa.pub root@172.17.17.37:/tmp/ ls /tmp/id_rsa.pub ~~~ 显示已经上传的密钥 `5.服务器上生成git用户,使用git用户并初始化gitosis` 增加git用户 ~~~ adduser -m git ~~~ 切换用户 ~~~ su - git ~~~ 服务器的公钥(刚才客户端上传的),导入后客户端即可以管理git服务器。 ~~~ gitosis-init < /tmp/id_rsa.pub ~~~ 显示以下信息即表示成功 ~~~ Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/ ~~~ 修改权限 ~~~ [root@localhost git]# chmod 755 repositories/gitosis-admin.git/hooks/post-update ~~~ 删除密钥 ~~~ su - root rm -rf /tmp/id_rsa.pub ~~~ `6.在客户端,复制git管理项目(git服务器管理,也是一个git仓库)` ~~~ mkdir -p /repo cd /repo git clone git@172.17.17.37:gitosis-admin.git ~~~ `7.在客户端,增加及设置管理项目` ~~~ cd /repo/gitosis-admin ~~~ 查看已经上传密钥 ~~~ ls keydir cat keydir/root\@localhost.localdomain.pub #root\@localhost.localdomain.pub为已经上传的客户端生成的公密 显示密钥最后的符串为密钥用户名,这里为root@localhost.localdomain ~~~ `vim gitosis.conf` ~~~ #在文件尾增加以下内容 [group test-git] # 组名称 writable = test-git # 项目名称 members = root@localhost.localdomain #密钥用户名 ~~~ ~~~ #提交修改 git add . git commit -a -m "add test-git repo" git push ~~~ `8.在客户端,初始,增加及使用项目test-git` ~~~ cd /repo mkdir test-git cd test-git git init touch readme git add . git commit -a -m "init test-git" git remote add origin git@172.17.17.37:test-git.git git push origin master ~~~ `9.在服务器映射自己的项目html.git` ~~~ [root@localhost repositories]# pwd /home/git/repositories [root@localhost repositories]# ln -s /usr/local/apache/htdocs/ html.git [root@localhost repositories]# ls gitosis-admin.git html.git ~~~ 修改 gitosis.conf配置文件 ~~~ [root@localhost git]# pwd /home/git [root@localhost git]# ls -al 总用量 40 drwx------ 7 git git 4096 7月 15 05:31 . drwxr-xr-x. 4 root root 4096 7月 15 05:25 .. -rw-r--r-- 1 git git 18 7月 18 2013 .bash_logout -rw-r--r-- 1 git git 176 7月 18 2013 .bash_profile -rw-r--r-- 1 git git 124 7月 18 2013 .bashrc drwxr-xr-x 2 git git 4096 7月 15 05:27 gitosis lrwxrwxrwx 1 git git 53 7月 15 05:27 .gitosis.conf -> /home/git/repositories/gitosis-admin.git/gitosis.conf drwxr-xr-x 2 git git 4096 11月 12 2010 .gnome2 drwxr-xr-x 4 git git 4096 11月 30 2013 .mozilla drwxr-xr-x 3 git git 4096 7月 15 05:29 repositories drwx------ 2 git git 4096 7月 15 05:27 .ssh [root@localhost git]# vim .gitosis.conf #添加以下代码: [group html] writable = html members = root@localhost.localdomain #进入html.git,初始化并赋权限 [root@localhost git]# cd repositories/html.git/ [root@localhost html.git]# git init [root@localhost html.git]# chmod -R 777 .git/ #修改配置 [root@localhost html.git]# git config receive.denyCurrentBranch ignore #更新库,因为是直接git init ,所以要执行以下操作,才能在服务器上更新库 [root@localhost html.git]# git reset --hard ~~~ ` 10.添加用户` 1):在客户端生成密钥并上传到服务器 ~~~ ssh-keygen -t rsa #一路回车 cd .ssh/ scp id_rsa.pub root@172.17.17.37:/tmp ~~~ 2):把上传的公钥复制到`/home/git/repositories/gitosis-admin.git/gitosis-export/keydir`(此步可以略过) ~~~ #查看公钥的内容 [root@localhost keydir]# cat /tmp/id_rsa.pub #移动公钥并重命名 [root@localhost keydir]# cp /tmp/id_rsa.pub /home/git/repositories/gitosis-admin.git/gitosis-export/keydir/Administrator@OADKY7QARNLQQUG.pub [root@localhost keydir]# ls Administrator@OADKY7QARNLQQUG.pub root@localhost.localdomain.pub ~~~ 3):把公钥内容添加到authorized_keys ~~~ [root@localhost .ssh]# pwd /home/git/.ssh [root@localhost .ssh]# ls authorized_keys [root@localhost .ssh]# cat /tmp/id_rsa.pub >>authorized_keys ~~~ 4):客户端访问服务器(注意:要用绝对路径) ~~~ git clone git@172.17.17.37:/home/git/repositories/html.git ~~~