CentOS 6.3 Build Git/gitosis/gitweb

Source: Internet
Author: User
Tags ssh access using git

1. Installation and configuration of Git

(1) Install git using yum source
    1. Yum Install git

(2) Create a git user and set a password

    1. #useradd--home/home/git git
    2. #passwd git
    3. Note here to set a password, it is recommended not to set a password, a lot of information on the Internet do not set a password
(3) Create a git repository to verify that Git is available
  • Before using Git, set two global variables for git in the following way:
    1. # git config--global user.name "Dylan"
    2. # git config--global user.email "[Email protected]"
  • Set permissions for the GIT repository directory
    1. # Su-git//switch to git user
    2. $ chmod-r 755/home/git//Modify permissions for a directory
  • Create and initialize a repository
    1. $ MKDIR/HOME/GIT/REPO//Assuming the repository to be created is placed in the/home/git/repo directory
    2. $ cd/home/git/repo
    3. $ mkdir Test_repo
    4. $ CD Test_repo
    5. $ git init--bare
  • Test whether the newly created repository is available
    1. Su-test (test for another user or exit, using the root user)
    2. $ cd/home/test
    3. $ mkdir Repos
    4. $ CD Repos
    5. $ git Clone/home/git/repo/test_repo
    If "Initialized empty Git repository in/home/git/repo/test_repo/.git/" is displayed, the successful clone has a local repository. It can then be developed under this repository, for example, by adding a Readme.txt file.
    1. $ CD Test_repo
    2. $ vim Readme.txt (Create a file)
    3. $ git Add. (Note that there is a [.] later)
    4. $ git commit-a
    5. $ GIT push origin master
Note: If there is an error at this point, the biggest reason is that Test_repo refs and the objects directory have insufficient permissions to do the following (the two directories under the GIT server side of repository).
    1. $ chmod-r 777 refs/
    2. $ chmod-r 777 objects/
2. Installation of Gitosis(1) Installation of Python-setuptools (because Gitosis's installation script is written in Python)
    1. #yum Install Python-setuptools
(2) Installation of gitosis
    1. #git clone git://github.com/res0nat0r/gitosis.git//Download gitosis to the directory you want to store
    2. #cd gitosis
    3. #python setup.py Install//If there is no error, the installation is successful

(3) Create the public key of the user who is using this git server

Because gitosis access is accessed via SSH, we also need to create an SSH access key. Find another machine (if conditions allow) to create a public key as a client machine for the GIT server and then upload it to the GIT servers. (If you want to make it easy, you can create a public key on a git server, either with a git user or another user.) For convenience, git servers are used and GIT users are employed.
    1. # Su-git
    2. $ ssh-keygen-t RSA
The public key is generated, the default is placed under/home/git/.ssh/id_rsa.pub, if the public key is generated when the password is set, pay attention to remember the password, in order to be simple, I do not set the password here. (4) Configure gitosis gitosis to git management by gitosis-admin.git this project to complete, GITOSIS-ADMIN.GIT project itself is placed under git management, so you need to first on the client side clone    Gitosis-admin.git, the changes can be submitted to Git server to take effect when modified according to requirements. The implication here is: where do you want to configure the gitosis, where you need to clone to Gitosis-admin.git.
    • Assuming that gitosis is on a different machine, use a git user to Gitosis-admin.git clone to local.
      1. git clone [email protected]:/home/git/repositories/gitosis-admin.git
    • Modify the gitosis configuration file gitosis.conf
      1. $ vim gitosis.conf
      2. You'll see something like this
      3. [Gitosis]
      4. [Group Gitosis-admin]
      5. writable = Gitosis-admin
      6. Members = [email protected]
      The gitosis.conf file is used to set the user, The control file for the repository and permissions (for the detailed meaning of the gitosis.conf file, and the role of the public key under the Keydir directory, will be written in another document, no longer detailed here), just know that the Gitosis repository is writable and the supported users have git
(5) New Add repository Modify gitosis-admin configuration file gitosis.conf, add a new repository, for example:
    1. [Gitosis]
    2. [Group Gitosis-admin]
    3. writable = Gitosis-admin
    4. Members = [email protected]
    5. [Group Test_repo]//new warehouse name added
    6. writable = TEST_REPO//read/write permission for this warehouse, writable here
    7. Members = [email protected] [email protected]//user name with access to this warehouse @ hostname
Suppose that when User1 to access this Test_repo repository, you need to enter the following command:

    1. git clone [email protected]_server_ip:/home/git/repo/test_repo.git

You will be asked to enter a password for User1, which is the password you entered when you created the User1 public key. So how gitosis to determine the identity of User1? This requires that the public key generated by the User1 must be passed on to the administrator in advance, that is, a manager who has permission to operate on Gitosis-admin, who then copies the public key to the Keydir directory, and then executes the git add,git push.

3. Gitweb Installation

Note: The ISO source for Redhat is no gitweb installation package, but there is a CentOS source, in the previous article on how to get Redhat to use the source of CentOS, then just use the following command to install.

    1. # yum Install Gitweb

4. Gitweb Configuration

Gitweb is installed by default under/var/www/git, its configuration file under/etc/gitweb.conf, and httpd configuration file/etc/httpd/conf.d/git.conf. (1) Modify/etc/gitweb.conf
    1. $projectroot = "/var/www/git"//change Projectroot to/var/www/git
(2) Modify/etc/httpd/conf.d/git.conf
    1. Alias/git/var/www/git
    2. <Directory/var/www/git>
    3. Allow from all
    4. AllowOverride All
    5. Order Allow,deny
    6. Options +execcgi
    7. AddHandler Cgi-script. CGI
    8. DirectoryIndex gitweb.cgi
    9. SETENV gitweb_config/etc/gitweb.conf
    10. Dav on
    11. Rewriteengine OFF
    12. </Directory>
(3) Restart httpd
    1. /ETC/INIT.D/HTTPD restart
(4) Connect the Gitosis warehouse to the/var/www/git to complete the web display
    1. Ln-s/home/git/repositories/test_repo.git/var/www/git/
(5) Browsing through the browser http://xxxx/git/Note: If git clone http://xxx/git/test_repo.git update-server-info error occurs, the Test_ The git update-server-info command can be executed under the Repos.git directory (gitosis the appropriate repository for the server). 5. Create a new git repositoryUnder Git server's/home/git/repository directory, execute the following command:
    1. mkdir Test.git
    2. CD Test.git
    3. Git init--bare
    4. You can add the source file here, or you can add it after the client-side clone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.