Ubuntu perfectly builds git server "turn"

Source: Internet
Author: User
Tags git client python script using git

Transferred from: http://blog.csdn.net/tommy_wxie/article/details/38779667

Recently the company project needs to use GIT to manage the project, just every weekend spent a little time in the virtual machine's unbuntu system to build the next git server, because the construction process encountered some small problems, and then because the personal memory is not very good, so record down here for a rainy day. I have already installed the virtual machine under the ubuntu12.04 system once, forget the record, this time again in the virtual machine ubuntu13.10 system next step to build, the following introduction includes the client machine (host machine Win7) installed Git client, and client git Bash is simple to use.

First, the software required to install the GIT server

Open terminal and enter the following command:

[SQL]View Plaincopyprint?
    1. ubuntu:~$ sudo apt-get install git-core openssh-server openssh-client

Git-core is GIT version control core software

Installing Openssh-server and openssh-client is because git needs to transfer files between the server and the client via the SSH protocol

Then there is a confirmation operation, enter Y and wait for the system to automatically download the software installation from the mirror server, after installation will return to the user's current directory. If

Installation prompt failed, probably because the System software Library index file is too old, first update on it, the Update command is as follows:

[SQL]View Plaincopyprint?
    1. ubuntu:~$ sudo apt-get update

Continue with the installation command above after updating the repository index.

Installing Python's setuptools and gitosis, because Gitosis's installation relies on some Python tools, we need to install Python first

The Setuptools.

Execute the following command:

[SQL]View Plaincopyprint?
    1. ubuntu:~$ sudo apt-get install Python-setuptools

This tool is relatively small, the installation is relatively fast, next ready to install Gitosis, install gitosis before you need to initialize the server git user information, this

Just fill it out.

[SQL]View Plaincopyprint?
    1. ubuntu:~$ git config --global user.name "MyName"
    2. ubuntu:~$ git config --global user.email "****** @gmail. com"


After initializing the server user information, you can install Gitosis, gitosis is mainly used to authorize the user, setting permissions is also very convenient.

You can get the Gitosis version file with the following command

[SQL]View Plaincopyprint?
    1. ubuntu:~$ git clone https://github.com/res0nat0r/gitosis.git

Note: Two in the middle are digital zeros

After getting the gitosis file, go to the file directory


[SQL]View Plaincopyprint?
    1. ubuntu:/tmp$ CD gitosis/

Then install it using the Python script of the setup.py in the command installation directory.


[SQL]View Plaincopyprint?
    1. ubuntu:/tmp/gitosis$ sudo python setup.py install


Here, the entire installation process is complete, and the following is a basic configuration of git.


II. Create a GIT administrator account, configure Git


Create an account (GIT) as an administrator on a git server that can manage project permissions for other users.

[SQL]View Plaincopyprint?
    1. ubuntu:/tmp/gitosis$ sudo useradd-m git
    2. ubuntu:/tmp/gitosis$ sudo passwd git


Then, create a project warehouse storage point under the/home directory, and set the GIT user to have all permissions, without any permissions from other users.

[SQL]View Plaincopyprint?
    1. ubuntu:/tmp/gitosis$ sudo mkdir/home/gitrepository
    2. ubuntu:/tmp/gitosis$ sudo chown git:git/home/gitrepository/
    3. ubuntu:/tmp/gitosis$ sudo chmod 700/home/gitrepository/


Because Gitosis will place the warehouse in the user's repositories directory by default, for example, the GIT user's warehouse address defaults to

/home/git/repositories/directory, here we need to create a link map. Let him point to the project that we created earlier for the purpose of storing

The Warehouse directory/home/gitrepository.

[SQL]View Plaincopyprint?
    1. ubuntu:/tmp/gitosis$ sudo ln-s/home/gitrepository/home/git/repositories

Here I will generate the SSH public key on the server side, and if I want to manage it on another machine, I can generate an SSH public key on the other machine.

[SQL]View Plaincopyprint?
    1. ubuntu:/home/git$ ssh-keygen-t RSA


You will be prompted to enter the password, we do not enter the direct carriage.

The gitosis is then initialized with the public key id_rsa.pub that was just generated.



A message appears stating that the gitosis has been initialized successfully.

Gitosis is mainly through the Gitosis-admin.git warehouse to manage some configuration files, such as user Rights Management. Here we need to have one of those

A post-update file to add executable permissions.

[SQL]View Plaincopyprint?
    1. ubuntu:/home/git$ sudo chmod 755/home/gitrepository/gitosis-admin.git/hooks/post-update


Third, create the project warehouse on the server


Use a git account to create a directory (Mytestproject.git) on the server and initialize it as a Git project repository.

[SQL]View Plaincopyprint?
    1. ubuntu:/home/git$ su git
    2. $ cd/home/gitrepository
    3. $ mkdir Mytestproject.git
    4. $ git init --bare
    5. $ exit

If the following information is present, a project warehouse named Mytestproject.git has been successfully created, and the new warehouse is temporarily empty.

, can not be clone by the client, but also need to do some configuration operation for Gitosis.


Iv. using Gitosis to manage permissions for user action items


You first need to clone the Gitosis-admin.git repository on the machine that generated the SSH public key (used to initialize the Gitosis) earlier.

Create a new directory on the client machine to hold the Gitosis-admin.git warehouse

[SQL]View Plaincopyprint?
    1. ubuntu:~$ mkdir Gitadmin
    2. ubuntu:~$ CD gitadmin/
    3. ubuntu:~/gitadmin$ git clone [email protected]:gitosis-admin.git


Clone will display the message correctly


Clone down will have a gitosis.conf configuration file and a Keydir directory. GITOSIS.CONF is used to configure the user's permission information,

Keydir the primary user to hold the SSH public key file (usually named "User name. Pub", the gitosis.conf configuration file needs to use the same user name), with

The client machine for the authentication request.


Now let the users who need authorization use the previous method to generate the corresponding SSH public key files on their own machine, the administrator will separate them by user name

Name it and copy it to the Keydir directory.

[SQL]View Plaincopyprint?
    1. ubuntu:~$ cp/home/aaaaa/desktop/zhangsan.pub/home/aaaaa/gitadmin/gitosis-admin/keydir/
    2. ubuntu:~$ cp/home/aaaaa/desktop/lisi.pub/home/aaaaa/gitadmin/gitosis-admin/keydir/


Continue editing the gitosis.conf file

[Gitosis]

[Group Gitosis-admin] # # # #管理员组
Members = [email protected] # # # #管理员用户名, you need to find the corresponding. pub file in the Keydir directory, separated by a number of available spaces (

Same below
writable = gitosis-admin### #可写的项目仓库名, separated by multiple available spaces (same as below)


[Group Testwrite] # # # #可写权限组
Members = zhangsan### #组用户
writable = mytestproject### #可写的项目仓库名


[Group testread]### #只读权限组
Members =lisi### #组用户
readonly= mytestproject### #只读项目仓库名


Because these configuration modifications are only locally modified, they also need to be pushed to the server to take effect.

[SQL]View Plaincopyprint?
    1. ubuntu:~/gitadmin/gitosis-admin$ git Add.
    2. ubuntu:~/gitadmin/gitosis-admin$ git commit-am "Add a user permission"
    3. ubuntu:~/gitadmin/gitosis-admin$ git push Origin master


Push success will display the following prompt message



Again after the new user cannot take effect immediately, this time need to restart the SSHD service

[SQL]View Plaincopyprint?
    1. ubuntu:~/gitadmin/gitosis-admin$ sudo/etc/init.d/ssh Restart


Now that the server's git is installed and configured, you need a privileged group of members on the respective machine to clone the corresponding

The Project warehouse is working accordingly.


V. Client (Windows) using Git


Download the GIT client software that installs the Windows version: http://msysgit.github.io/

After the installation is complete, there are several Git-related menu options on the right-click menu, which we use primarily with the GIT bash command line.

Create a new directory locally, use Git to initialize the directory, and then create a new text file for testing and finally associated to the GIT server repository

And finally upload the local version to the server.

[SQL]View Plaincopyprint?
    1. $ mkdir Testgit
    2. $ CD Testgit
    3. $ git init
    4. $ echo "This was a Test text File,will push to Server" > Hello.txt
    5. $ git Add.
    6. $ git commit-am "Init a base version,add a first file for push to server"
    7. $ git Remote add origin [email protected]:mytestproject.git
    8. $ GIT push origin master


In this way the server has created a basic version of a Mytestproject.git repository, and now other members can just clone from the server

The

Under window, go to the local directory where you want to clone, right-click the GIT bash option, enter

[SQL]View Plaincopyprint?
    1. $ git clone [email protected]:mytestproject.git


You can clone the project to a local repository.

The following is a simple modification and commit operation

[SQL]View Plaincopyprint?
    1. $ CD MyTestProject
    2. $ echo "This was another text file created by other" >another.txt
    3. $ git Add.
    4. $ git commit-am "Add a another file by other"
    5. $ GIT push origin master


The final push to the server successfully displays the following information

Top
1
Step

Ubuntu perfectly builds git server "turn"

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.