Git server built under CentOS: Gitosis

Source: Internet
Author: User
Tags git client ssh port

Git server built under CentOS: Gitosis

Due to the low cost, I rented a virtual private cloud (vps) from miguo, and the domestic git server is about to expire. I plan to deploy one on it because I have encountered many problems. This article mainly records some problems in the process.

Gitosis Introduction

Gitosis is a software that facilitates the setup of central servers through Git and ssh. Therefore, the Gitosis service environment requires git and ssh configuration on the server. Generally, the purchased vps has installed the ssh service, so ssh does not need to be installed manually.

Preparations
  1. Create a user and group dedicated to git, usually called "git"
  2. Install git
  3. Create a git user's public key (pub)
  4. Install ssh (if not)

1. Create a user

#useradd git#passwd git

2. Install git using the yum source in the example. If your environment does not have yum, you can use apt

yum install git

3. Create a git Public Key

# Su-git // switch from the root user to the git user $ ssh-keygen-t rsa // execute the git command to generate a public key (if it cannot be executed here, check whether the git client is successfully installed)

At this point, the Public Key is generated and put under/home/git/. ssh/id_rsa.pub by default. If a password is set when the public key is generated, remember the password.

Gitosis installation and configuration1. Install python support tools (pyhton is required for gitosis installation scripts)
#yum install python-setuptools
2. Install Gitosis
#git clone git://github.com/res0nat0r/gitosis.git#cd gitosis#python setup.py install
3. initialize the gitosis-admin.git Library

Many articles do not describe the role of the gitosis-admin.git library, I would like to mention here, gitosis-admin.git is a git repository for gitosis management. This git repository is very useful, and new members and new git repositories need to be added in the future.

sudo -H -u git gitosis-init 

After the command is initialized, a directory "/repositories" is created under/home/git to store all git repositories.

4. Configure gitosis-admin

Because gitosis is managed by a gitosis-admin.git project and the gitosis-admin.git itself is a git repository, you need to use the client side to clone it and modify the commit to take effect.

git clone ssh://git@127.0.0.1:26732/gitosis-admin.git

Run the git command to clone gitosis-admin. here you need to pay attention to the port problem (this port is the same as the ssh remote port for vps. Many tutorials on the Internet use the default port)

5. Add a new gitosis user client:

Use git-base on a local computer to upload pub to the gitosis server. If the local computer does not have pub, see: preparations for this article: 3. Create a git public key.

scp -P 26732 ~/.ssh/id_rsa.pub git@23.83.xxx.xxx:/tmp

Explain the above command:Scp is an upload function of git.-P is followed by the ssh portGit @ is the git user of the corresponding server/Tmp is the directory that pub uploads to the server (Note: git users must have the write permission on tmp)

Server operation:

Copy the pub that has just been uploaded to tmp to gitosis-admin (Note: The gitosis-admin directory is cloned on top, so do not make a mistake)

cp /tmp/id_rsa.pub  /home/git/gitosis-admin/keydir/cheukho.chen@localhost.localdomain.pub

Modify the gitosis configuration file and add pub to the management of gitosis-admin.

vi /home/git/gitosis-admin/gitosis.conf

The following content is displayed:

[Gitosis] [group gitosis-admin] writable = gitosis-admin members = git@localhost.localdomain.pub

Append the name of cp pub to members and separate it with spaces.

[Gitosis] [group gitosis-admin] writable = gitosis-admin members = git@localhost.localdomain.pub cheukho.chen@localhost.localdomain.pub

After the modification is completed, use the git command to submit the modification to take effect.

git add .git commit -am "add new user pub"git push
6. Add a new repository

Modify gitosis-admin Configuration

vi /home/git/gitosis-admin/gitosis.conf

Add

[Group test] writable = test members = git@localhost.localdomain cheukho.chen@localhost.localdomain

After the modification is completed, use the git command to submit the modification to take effect.

git add .git commit -am "add new user pub"git push
Client-side git operations

The pub of the client must be configured on Gitosis. Note that the port of the vps is always stuck with me before the port problem occurs.

git clone ssh://git@23.83.xxx.xxx:26732/test.git
FAQs

1. first make sure that/home/git/repositories/gitosis-admin.git/hooks/post-update is executable and the property is 0755

2. Enter the password for git operationsCause: the password is not found.Solution: Upload id_pub.rsa to keydir and change it to 'gitosis account. pub', for example, miao. pub. Extension. pub cannot be omitted

3. ERROR: gitosis. serve. main: Repository read access denied ** cause: ** gitosis. members in conf is inconsistent with the user name in keydir. For example, members = foo @ bar in gitosis, but the public secret name in keydir is foo. pubSolution: Make the keydir name consistent with the name specified by members in gitosis. Change members = foo or password name to foo@bar.pub

4. the following error occurs: Unable to create temporary file: Permission denied.Cause: the server's warehouse directory does not have the write permissionSolution: Run/home/git/repositories # chown-R git */home/git/repositories # chgrp-R git *

Reference: http://www.oschina.net/question/12_72988 http://witmax.cn/git-setup.html

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.