1. ホーム
  2. サーバー

centos build git サーバー (以上)

2022-03-17 07:41:23

Gitはオープンソースの分散型バージョン管理システムで、非常に小規模なものから大規模なものまで、様々なプロジェクトのバージョン管理を効率的かつ迅速に行うことができます。

[root@163-44-167-134 ~]# yum -y install git
# check git version number
[root@163-44-167-134 ~]# git --vistion
# gitosis is a python package that manages user permissions by managing the server's /home/git/.ssh/authorized_key file
[root@163-44-167-134 ~]# yum -y install python python-setuptools
[root@163-44-167-134 ~]# git clone git://github.com/res0nat0r/gitosis.git
[root@163-44-167-134 ~]# cd gitosis/
[root@163-44-167-134 ~]# python setup.py install
# show Finished processing dependencies for gitosis==0.2 means success
# add git user
[root@163-44-167-134 ~]# useradd git  
[root@163-44-167-134 ~]# su git 
[git@163-44-167-134 root]$ cd ~
# git manage user production keys and upload them to the server side
#Some people put the git admin user and the git server on two servers, which is completely unnecessary
[git@163-44-167-134 ~]$ ssh-keygen -t rsa 
[git@163-44-167-134 ~]$ gitosis-init <~/.ssh/id_rsa.pub
# error reported
Traceback (most recent call last):
  File "/usr/bin/gitosis-init", line 9, in <module>
    load_entry_point('gitosis==0.2', 'console_scripts', 'gitosis-init')()
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 24, in run
    return app.main()
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 38, in main
    self.handle_args(parser, cfg, options, args)
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 123, in handle_args
    user = ssh_extract_user(pubkey)
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 39, in ssh_extract_user
    raise InsecureSSHKeyUsername(repr(user))
gitosis.init.InsecureSSHKeyUsername: Username contains not allowed characters: 'git@163-44-167-134'
[git@163-44-167-134 ~]$ vim ~/.ssh/id_rsa.pub
# change git@163-44-167-134 at the end of the certificate to git@localhost 
#This step can be ignored if you don't report an error
[git@163-44-167-134 ~]$ gitosis-init <~/.ssh/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/
[git@163-44-167-134 ~]$ ls
gitosis repositories
[git@163-44-167-134 ~]$ mkdir github
[git@163-44-167-134 ~]$ cd github/
[git@163-44-167-134 github]$ git clone [email protected]:gitosis-admin.git
Cloning into 'gitosis-admin'...
The authenticity of host '163.44.167.134 (163.44.167.134)' can't be established.
ECDSA key fingerprint is a1:e3:dc:f2:aa:49:3b:5f:9f:93:0f:dd:6e:d4:ed:32.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '163.44.167.134' (ECDSA) to the list of known hosts.
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 5 (delta 0)
Receiving objects: 100% (5/5), done.
# This clones the configuration
[git@163-44-167-134 github]$ cd gitosis-admin/
[git@163-44-167-134 gitosis-admin]$ ls
gitosis.conf keydir
#gitosis.conf is the configuration project and user files, keydir is the public key directory
[git@163-44-167-134 gitosis-admin]$ vim gitosis.conf
[gitosis]

[group gitosis-admin]
members = git@localhost
writable = gitosis-admin
# Modify this (add a project) 
[group github]
writable = github
members = git@localhost
[git@163-44-167-134 gitosis-admin]$ cd ... /... /repositories/
[git@163-44-167-134 repositories]$ mkdir github.git
[git@163-44-167-134 repositories]$ cd github.git/
# initialize a project
[git@163-44-167-134 github.git]$ git init --bare
Initialized empty Git repository in /home/git/repositories/github.git/
[git@163-44-167-134 root]$ cd ~
[git@163-44-167-134 ~]$ mkdir test
[git@163-44-167-134 ~]$ cd test/
[git@163-44-167-134 test]$ git clone [email protected]:github.git
Cloning into 'github'...
warning: You appear to have cloned an empty repository.
[git@163-44-167-134 github]$ touch test1.txt
#add
[git@163-44-167-134 github]$ git add .
#commit
[git@163-44-167-134 github]$ git commit -a -m "granted jay commit rights to git-test"
# report error
fatal: Not a git repository (or any of the parent directories): .git
[git@163-44-167-134 github]$ cd gitosis-admin/
[git@163-44-167-134 gitosis-admin]$ git add .
[git@163-44-167-134 gitosis-admin]$ git commit -a -m "granted jay commit rights to git-test"

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for <git@163-44-167-134.(none)>) not allowed
#Whatever
[git@163-44-167-134 gitosis-admin]$ git config --global user.name "gituser"    
[git@163-44-167-134 gitosis-admin]$ git config --global user.email "[email protected]"
# commit again
[git@163-44-167-134 github]$ git commit -a -m "granted jay commit rights to git-test"
[master (root-commit) dc1958d] granted jay commit rights to git-test
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test1.txt
#commit to the main version
[git@163-44-167-134 gitosis-admin]$ git push origin master


上記はすべて1台のサーバで動作していますが、ユーザは2人です。ここでgitサーバーの構築は完了です。