Ubuntu perfectly builds git server "turn"

Source: Internet
Author: User
Tags git client python script

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, install the GIT server required software open Terminal Enter the following command: [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~$ sudo apt-GetInstall Git-core openssh-server openssh-client git-Core is the GIT version control kernel software Installation OpenSSH-server and openssh-The client is because git needs the SSH protocol to transfer files between the server and the client, 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 the installation prompt fails, it may be because the System software Library index file is too old, first update on it, the Update command is as follows: [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~$ sudo apt-GetUpdate the repository index after updating to continue with the installation command above. Installing Python's setuptools and gitosis, because Gitosis's installation relies on some Python tools, we need to install Python's setuptools first. Execute the following command: [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~$ sudo apt-GetInstall 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 casually fill. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~$ git config--GlobalUser.Name"myname"Ubuntu:~$ git config--GlobalUser.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 by using the following command [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~$ git clone https://Github.com/res0nat0r/gitosis.gitNote: In the middle there are two numbers 0 get the gitosis file after getting into the file directory [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:/tmp$ CD gitosis/Next, use the Python command to install the setup.py Python script in the directory [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:/tmp/gitosis$ sudo python setup.py install here, the entire installation process is complete, and the following is a basic configuration of git. Second, create a GIT administrator account, configure Git to create an account (git) as a git server administrator, you can manage the project permissions of other users. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:/tmp/gitosis$ sudo useradd-m git ubuntu:/tmp/gitosis$ sudo passwd git and then/The home directory creates a project warehouse storage point, and sets only the GIT user to have all permissions, and no other user has any permissions. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:/tmp/gitosis$ sudo mkdir/home/gitrepository Ubuntu:/tmp/gitosis$ sudo chown git:git/home/gitrepository/Ubuntu:/tmp/gitosis$ sudo chmod the/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. Get him to point to the warehouse directory that we created earlier that was dedicated to storing the project./home/gitrepository. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:/tmp/gitosis$ sudo ln-s/home/gitrepository/home/git/repositories Here I will generate an 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?On code , view the snippet that derives from my code slice ubuntu:/home/git$ Ssh-keygen-t RSA here will prompt 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 gitosis-Admin.git Warehouse to manage some configuration files, such as the management of user rights. Here we need a post for one of them-update file to add executable permissions. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:/home/git$ sudo chmod755/home/gitrepository/gitosis-admin.git/hooks/post-update Three, create a project warehouse on the server use a git account to create a directory on the server (MYTESTPROJECT.GIT) and initialize it to the GIT project repository. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:/home/git$ su git $ cd/home/gitrepository $ mkdir mytestproject.git $ git init--Bare $ exit If you have successfully created a project repository named Mytestproject.git, the new warehouse is temporarily empty, cannot be clone by the client, and requires some configuration operations on gitosis. Iv. using Gitosis to manage the permissions of the user action item first requires the machine on which the SSH public key was generated earlier (used to initialize gitosis) gitosis-Admin.git's Warehouse clone down. Create a new directory on the client machine to store gitosis-admin.git Warehouse [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~$ mkdir gitadmin ubuntu:~$ CD gitadmin/Ubuntu:~/gitadmin$ git clone [email protected]192.168.1.106: gitosis-Admin.git Clone correctly displays the information 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), the client machine used to authenticate the 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 named them according to the user name, and copied to the Keydir directory. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~$ cp/home/aaaaa/desktop/zhangsan.pub/home/aaaaa/gitadmin/gitosis-admin/keydir/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 several available spaces (same as) writable= gitosis-admin### #可写的项目仓库名, multiple available spaces (same as) [group Testwrite] # # # #可写权限组members=zhangsan### #组用户writable=mytestproject### #可写的项目仓库名 [group Testread] # # #只读权限组members=lisi### #组用户ReadOnly=mytestproject### #只读项目仓库名因为这些配置的修改只是在本地修改的 and will need to be pushed to the server to take effect. [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~/gitadmin/gitosis-admin$ git Add. Ubuntu:~/gitadmin/gitosis-admin$ git commit-am"Add a user permission"Ubuntu:~/gitadmin/gitosis-admin$ git push origin master push success will display the following prompt and after the new user does not take effect immediately, it is necessary to restart the sshd service [SQL] View Plaincopyprint?On code , view the snippet that derives from my code slice ubuntu:~/gitadmin/gitosis-admin$ sudo/etc/init.d/SSH Restart now that the server's git is installed and configured, it needs the right group of members to work on the corresponding project repository on their own machine. V. Client (Windows) uses git to 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, then create a new text file for testing, and then link to the relevant project in the GIT server repository, and finally upload the local version to the server. [SQL] View Plaincopyprint?look at code on the snippet derivation to my Code slice $ mkdir testgit $ cd testgit $ git init $ echo"This was a test text File,will push to server">hello.txt $ git Add. $ git commit-am"Init a base version,add a first file for push to server"$ git Remote add origin [email protected]:mytestproject.git $ Git push origin master so the server creates a MYTESTPROJECT.G It's a basic version of the warehouse, and now the rest of the crew just have to clone from the server. Under window, go to the local directory where you want to clone, right-click the GIT bash option, enter [SQL] View Plaincopyprint?On code , view the snippet to derive from my code slice $ git clone [email protected]:mytestproject.git can clone the project to the local repository. The following is a simple modification and commit operation [SQL] View Plaincopyprint?look at code on the snippet to derive to my Code slice $ cd MyTestProject $ echo"This is another the text file created by other">another.txt $ git Add. $ git commit-am"Add a another file by other"$ Git push origin master last push to server success will display the following information

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.