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?
- 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?
- 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?
- 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?
- ubuntu:~$ git config --global user.name "MyName"
- 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?
- 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?
- ubuntu:/tmp$ CD gitosis/
Then install it using the Python script of the setup.py in the command installation directory.
[SQL]View Plaincopyprint?
- 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?
- ubuntu:/tmp/gitosis$ sudo useradd-m git
- 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?
- ubuntu:/tmp/gitosis$ sudo mkdir/home/gitrepository
- ubuntu:/tmp/gitosis$ sudo chown git:git/home/gitrepository/
- 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?
- 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?
- 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?
- 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?
- ubuntu:/home/git$ su git
- $ cd/home/gitrepository
- $ mkdir Mytestproject.git
- $ git init --bare
- $ 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?
- ubuntu:~$ mkdir Gitadmin
- ubuntu:~$ CD gitadmin/
- 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?
- 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 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?
- 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 message
Again after the new user cannot take effect immediately, this time need to restart the SSHD service
[SQL]View Plaincopyprint?
- 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?
- $ 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
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?
- $ 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?
- $ CD MyTestProject
- $ echo "This was another text file created by other" >another.txt
- $ git Add.
- $ git commit-am "Add a another file by other"
- $ GIT push origin master
The final push to the server successfully displays the following information
-
Top
-
1
-
Step
Ubuntu perfectly builds git server "turn"