设为首页 收藏本站
查看: 2189|回复: 0

[经验分享] centos 安装git server

[复制链接]

尚未签到

发表于 2015-3-31 08:54:37 | 显示全部楼层 |阅读模式
  1.yum install lrzsz wget git
  
2.安装gitosis:gitosis为Git用户权限管理系统,通过管理服务端的/home/git/.ssh/authorized_key文件来执行对用户权限的管理,是一个python模块包
  #yum install python python-setuptools
  #git clone git://github.com/res0nat0r/gitosis.git
  #cd gitosis/
  #python setup.py install
  显示Finished processing dependencies for gitosis==0.2即表示成功

3.
  访问Gitolite需要通过SSH 密钥来验证。在用作GIT客户端的电脑上如果还没有密钥(一个公钥,一个私钥),那么可以使用ssh-keygen命令生成,然后将公钥拷贝到GIT服务器上。
  $ ssh-keygen -t rsa -C "your_mail@youremail.com"
  这里我们没有指定生成的密钥文件名称(可以通过-f filename指定),因此生成的文件为id_rsa和id_rsa.pub,前者是私钥,后者是公钥。另外,在Linux下执行ssh-keygen可以同时指定该密钥主人的email,这将出现在SSH公钥内容中。
在Gitolite建立的GIT服务器上,是通过修改gitolite-admin.git这个代码库中的源代码来创建新的代码库、为GIT客户添加登录用的公钥的。所以要管理Gitolite,必须有一个git virtual user去git clone出gitolite-admin.git的代码,这也就需要在服务器本机建立一对SSH密钥。

添加git用户
adduser --system --shell /bin/sh --comment 'git version control' --create-home  --home-dir /home/git git
cd /home/git
rz  选择你生成的ssh-key

4.su git

gitosis-init < ./id_rsa.pub
chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update


5.使用puttykeygenerator  转换 pub为ppk
  在Linux下产生的私钥文件putty是不认识的,putty只认识自己的ppk格式,要在这两种格式之间转换,需要PuTTYgen这个程序。
  
  在安装tortoisegit的时候会提示有选择项:
DSC0000.jpg
  如果选择第一个,在安装后配置git的时候就需要注意一些东西,如果选择第二项则git的连接都是通过ssh完成,后续配置简单一些。
  选择plink模式在git clone的时候需要加载ppk
DSC0001.jpg
  putty key的生成方式:
  启动putty key generator
DSC0002.jpg
  点击load按钮将刚才最先生成的ssh中的密钥id_rsa文件导入,然后弹出对话框提示导入成功,接着点击save private key来保存ppk文件,最后在git clone的对话框中加载ppk文件即可,连接的时候会提示输入git用户的密码,输入一下即可git clone gitosis的配置文件。
  如果选择ssh模式的tortoisegit,那么就无需配置ppk,直接git clone。
  这里在对话框中的git url填写的时候需要注意,是直接写gitosis-admin.git,而不是加有/home/git的绝对路径了。
  
  6.如果是直接在linux服务器上git clone,那么要注意路径问题:
  
  git clone git@localhost:/home/git/repositories/gitosis-admin.git
  否则写会提示:





1fatal: 'gitosis-admin.git' does not appear to be a git repository



2fatal: The remote end hung up unexpectedly
  
  如果是windows下,不要加用户名和绝对路径否则会报错

ERROR:gitosis.serve.main:Repository read access denied
  
  git clone git@localhost:gitosis-admin.git
  
  
  7.gitosis.conf
  [gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = root@vm1        #显示用户root@vm1.pub是初始化gitosis公钥的拥有者,是唯一能管理gitosis-admin项目的人
[group jay_fans]            #组名称
members = root@vm1        #密钥用户名  多个用户名使用 空格隔开  xx@xx aa@aa
writable = git-test                #项目名称  
  
  
  三、常见问题

首先确定 /home/git/repositories/gitosis-admin.git/hooks/post-update 为可执行即属性为 0755
1. git操作需要输入密码

原因公密未找到 解决上传id_pub.rsa到keydir并改为'gitosis帐号.pub'形式,如miao.pub。扩展名.pub不可省略
2. ERROR:gitosis.serve.main:Repository read access denied

原因gitosis.conf中的members与keydir中的用户名不一致,如gitosis中的members = foo@bar,但keydir中的公密名却叫foo.pub解决使keydir的名称与gitosis中members所指的名称一致。
改为members = foo 或 公密名称改为foo@bar.pub

  (3)出现’gitosis-admin’ does not appear to be a git repository,短路径无效时替换为全路径
  在服务器上使用短路径会取现下面这个问题,原因是没有找到对应匹配的密钥所致,如果正确使用了ssh密钥则不会出现这个问题,这里就不去折腾了

root@stu-system:/home/git/repositories# git clone git@127.0.0.1:gitosis-admin.git
Cloning into gitosis-admin...
git@127.0.0.1's password:
fatal: 'gitosis-admin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
  使用以下命令解决,只不过每次push和pull的时候都需要输入一遍git用户的密码,略为繁琐

git clone git@127.0.0.1:/home/git/repositories/gitosis-admin.git
  (4)出现Unable to create temporary file: Permission denied
在Windows上使用TortoiseGit执行Push时出现以下错误

git.exe push --force --progress  "origin" master:master
Counting objects: 189, done.
Compressing objects: 100% (187/187)
Writing objects:   7% (14/189)
fatal: Unable to create temporary file: Permission denied
fatal: sha1 file '' write error: Invalid argument
error: failed to push some refs to 'git@10.73.4.46:channelv.git'
git did not exit cleanly (exit code 1)
  原来是服务器上是用root账户建立的库目录,导致git账户无权写入,方法就是修改文件夹的所属用户和所属用户组

root@stu-system:/home/git/repositories# chown -R git *
root@stu-system:/home/git/repositories# chgrp -R git *
  (5)出现failed to push some refs to ‘git@10.73.4.46:channelv.git’
  在Windows上使用TortoiseGit执行Push时出现以下错误

git.exe push --progress  "origin" master:master
Counting objects: 189, done.
Compressing objects: 100% (158/158)
Writing objects: 100% (189/189), 1016.00 KiB | 997 KiB/s
Writing objects: 100% (189/189), 1.12 MiB | 997 KiB/s, done.
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git@10.73.4.46:channelv.git
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git@10.73.4.46:channelv.git'
git did not exit cleanly (exit code 1)
  在服务器对应的库目录下执行以下命令增加配置即可

git config --bool core.bare true


  6. 在git clone出gitolite-admin.git的代码的时候,可能会出现”Agent admitted failure to sign using the key”这个问题,然后让我们输入hosting user的密码。
  $ git clone git@localhost:gitolite-admin.git
Cloning into 'gitolite-admin'...
Agent admitted failure to sign using the key.
git@localhost's password:
Permission denied, please try again.
git@localhost's password:
Permission denied, please try again.
git@localhost's password:
Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly
$
  这是SSH的问题。参考资料[3]中提供了解决方法:
  https://help.github.com/articles/error-agent-admitted-failure-to-sign
  
  

Gitosis Server 设定专案、新增帐号


  • Gitosis 的专案权限 / 帐号管理 是使用 Git 来管理, 专案名称: gitosis-admin.git
  • git clone gitosis@localhost:gitosis-admin.git # 因为 Gitosis 是用 gitosis-admin.git 来管理, 所以需要抓下来修改、设定(未来所有管理也是如此)
  • cd gitosis-admin # 会看到下述

    • gitosis.conf # 设定档, 设定谁可以读写哪个专案的 Repository
    • keydir # 目录, 放每个帐号的 public key. 放置的档案命名: user1.pub, user2.pub (user1, user2.. 为帐号名称, 请自行修改)



新增帐号


  • cp /tmp/id_rsa_user1.pub keydir/user1.pub # 请依照实际帐号命名, 不要取 user1, user2
  • cp /tmp/id_rsa_user2.pub keydir/user2.pub
  • git add keydir/user1.pub keydir/user2.pub
  • git commit -m 'add user1, user2 public key'
  • git push
  • 注意: gitosis 认定的帐号, 是 id_rsa.pub 最后面 "xxx@example.com", 以 @ 前面的 "xxx" 为帐号(此帐号也是 gitosis 设定的帐号), 若帐号不同, git push 就会出现如下述的错误
      ERROR:gitosis.serve.main:Repository read access denied
    fatal: The remote end hung up unexpectedly



设定专案权限


  • vim gitosis.conf # 会看到下述, 不要动他, 于最下方设定自己的 Group / 专案名称即可.
      [group gitosis-admin]
    writable = gitosis-admin
    members = admin@example.com


  • 增加下述, myteam 是 group name, 此 group 有 user1, user2 的使用者, 可以写入 project_name.git 的专案
      [group myteam]
    writable = project_name
    member = user1 user2


  • git commit -m 'add user1, user2 write access to project_name' -a
  • git push

建立专案


  • cd ~/
  • mkdir project_name
  • cd project_name
  • git init
  • git remote add origin gitosis@example.com:project_name.git # gitosis 会自行于 /srv/gitosis/repositories 新增
  • touch readme
  • git add .
  • git commit -m 'initial'
  • git push origin master:refs/heads/master # 或 git push origin master

gitosis.conf 更多设定条件
  下述摘录自: Gitosis - ArchWiki

  [gitosis]
gitweb = yes
  [repo foobar]
description = git repository for foobar
owner = user
  [group devs]
members = user1 user2
  [group admins]
members = user1
  [group gitosis-admin]
writable = gitosis-admin
members = @admins
  [group foobar]
writable = foobar
members = @devs
  [group myteam]
writable = free_monkey
members = jdoe

  下述摘录自: Pro Git 服务器上的 Git 权限管理器 Gitosis

  [group mobile]
writable = iphone_project
members = scott josie jessica
  [group mobile_ro]
readonly = iphone_project
members = john


开放 Gitosis 公开存取


  • sudo -u gitosis git-daemon --base-path=/srv/gitosis/repositories/ --export-all

常用命令
  下述全部都在 gitosis-admin.git 内操作

新增帐号


  • cp /tmp/id_rsa_user1.pub keydir/user1.pub
  • vim gitosis.conf # 增加 members

设定专案


  • vim gitosis.conf # 增加 group、writeable 的项目

新增专案


    • mkdir project_name; cd project_name
    • git init
    • git remote add origin gitosis@example.com:project_name.git
    • git commit
    • git push origin master

  
  最好在 /srv/gitosis/repositories
  mkdir project
  cd project
  git init --bare
  
  
  https://wiki.archlinux.org/index.php/Gitosis#Public_access

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-52364-1-1.html 上篇帖子: 在 CentOS 6.x 上安装最新版本的 git 下篇帖子: CentOS下搭建使用gitlab 和tortoiseGit使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表