It takes some time to configure the GIT server and client. As before, it is still based on the latest ubuntu11.10 server/desktop system.
Thanks to the authors of these articles:
Http://www.hackido.com/2010/01/installing-git-on-server-ubuntu-or.html
For more information, see:
Http://www.debuntu.org/ssh-key-based-authentication this article describes how to generate an SSH public key and private key.
This article introduces some of the shortcomings of the first article.
Http://www.jiangmiao.org/blog/1600.html
This article introduces the parameters of the SSH-keygen command.
Http://lamp.linux.gov.cn/OpenSSH/ssh-keygen.html
My Installation Steps mainly come from the first article referenced above and supplement the deficiencies (for example, the first article of the original article is not clearly stated by the author ).
Note: git is a distributed management tool, so there is no real server. This article uses three machines, which are
S1 represents the Ubuntu 11.10 server in the IDC
C1 represents the first Ubuntu Desktop with administrative permissions
C2 represents the later added Ubuntu Desktop with management Permissions
All three machines can be considered as servers. From the perspective of convenience, project files are always submitted to S1, and the latest project files are obtained from S1.
1. Install the GIT service program on Ubuntu Server
This Ubuntu server is called S1
sudo apt-get install git-core
2. Install the gitosis program on S1.
Gitosis is a tool program that can help us with GIT repository access control and remote management.
sudo apt-get install python-setuptoolsmkdir ~/srccd ~/srcgit clone https://github.com/res0nat0r/gitosis.git
cd gitosissudo python setup.py install
3. Create a git account on S1.
No password. This account is used by the gitosis program.
sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git
4. Install the remote management client
The first remote management client is called C1.
sudo apt-get install openssh-clientssh-keygen
If openssh-client is not installed, the first line of command is required. The SSH-keygen command creates a public key and a private key file. Copy the public key file to the server. After being imported to gitosis on S1, C1 can connect to the server through SSH without the user name and password.
scp /home/chenshu/.ssh/id_rsa.pub cncm@S1:/home/cncmsudo -H -u git gitosis-init < /home/cncm/id_rsa.pub
The following result is displayed:
Initialize empty git repository in/home/git/repositories/gitosis-admin.git/
Reinitialized existing git repository in/home/git/repositories/gitosis-admin.git/
It means that the repository directory has been successfully created on S1. The path is/home/git/repositories, and an administrator repository named gitosis-Admin is also created.
Modify the permissions of a file on S1:
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
Clone the gitosis-Admin repository From S1 to C1:
/home/chenshu/my_gitcd ~/my_git
git clone git@S1:gitosis-admin.gitCloning into gitosis-admin...remote: Counting objects: 5, done. remote: Compressing objects: 100% (4/4), done. remote: Total 5 (delta 1), reused 5 (delta 1) Receiving objects: 100% (5/5), done.Resolving deltas: 100% (1/1), done.
Now you can remotely manage the repository on S1 by modifying the gitosis-admin/gitosis. conf file:
[gitosis][group gitosis-admin]members = chenshu@chenshu-System-Product-Namewritable = gitosis-admin
The above is automatically created when gitosis initialized the public key imported into C1. The C1 user has been added to the Administrator.
Note: You can also complete this operation on the server, not necessarily on the client.
5. Add a new user
Now another Ubuntu client C2, users also want to join in to use the CRF project and manage the GIT repository.
Users of the C2 machine generate public and private key files on C2 and pass the public key files to users of C1 (because C1 users are now administrators)
~/my_git/gitosis-admin$ mv ~/id_rsa.pub ./keydir/root@s15438266.onlinehome-server.com.pub
The above command is to copy the public key file id_rsa.pub generated by C2 on C1 to the/home/chenshu/my_git/gitosis-admin/keydir directory and rename it to the root@s15438266.onlinehome-server.com.pub
The file name is based on the username in id_rsa.pub.
[group gitosis-admin]members = chenshu@chenshu-System-Product-Name root@s15438266.onlinehome-server.comwritable = gitosis-admin
Modify the gitosis. conf file, add the root@s15438266.onlinehome-server.com (remove the. Pub suffix) to the gitosis-Admin group, that is, the root@s15438266.onlinehome-server.com.pub becomes the Administrator
Under the gitoosis-Admin directory, submit the settings to the server:
git add .git commit -am'add a new user'git push
Now try it on C2:
git clone git@S1:gitosis-admin.git
OK. The directory is obtained successfully.
6. Create a new project
Edit the gitsosis. conf file on C1 and add
[group cml]members = chenshu@chenshu-System-Product-Name root@s15438266.onlinehome-server.comwritable = cml
The [Group NML] Section represents the new group (Project NML). Users of C1 and C2 are also added. Submit the configuration file first.
git add .git commit -am'add a new project named cml'git push
Then add the real project file. In the top-level directory, I am creating the project directory NCS under/home/chenshu/my_git/, copying the required project files to the NCs, and then executing the following command, add the following to the S1 Server:
A. Git file is created in CD cmlgit init // The. Git file contains the framework of the GIT version library.
Touch xgit add. git remote add origin git @ S1: CRF. git // you can add. run git commit-am 'add NML project' git push origin master: refs/heads/Master
7. Obtain the NML Project
Run
git clone git@S1:cml.git
Then you can obtain the projects that have just been added to S1.
8. Notes when writing scripts for automatic compilation and deployment
If you want to write a script on C2 to automatically obtain the latest code from S1, note the following:
1. First, you cannot set a password for the Public Key generated earlier. Otherwise, you are required to enter the password every time you run git pull.
2. Do not submit the intermediate compilation files in the project to S1, such as the build directory files in the cmake project and the files in the target directory in the maven project. Otherwise, the next time you use git pull on clients such as C2, an error similar to this will be reported:
Error: untracked working tree file 'public/images/icon.gif 'wocould be overwritten by merge.
You must run the following command to fix the problem:
git reset --hard HEADgit clean -f -dgit pull
9. Change the default port
Port ssh22 is used by default, that is, port 22 for connecting git to the remote server. What if the server changes the port number, such as 443?
Under the root directory of your current project, there is a. Git directory. Open the config file and modify the URL in the [remote "Origin"] section:
Url = SSH: // git @ S1: 443/CRF. Git
# Url = git @ S1: CRF. Git
If no project exists, you need to clone it. Run the following command:
Git clone SSH: // git @ S1: 443/CRF. Git
10. Git add violates intuition for multiple purposes
The simplest method is to add an untracked file to git;
Inexplicably, if a file that has been tracked has been modified, you must add it again to change its status to staged, that is, it is recorded in the staged area and modified; otherwise, the subsequent commit operations will directly ignore it ;. Therefore, before commit, it is necessary to use git status to confirm that all the modified files are already in staged area. It is really tedious. In fact, sometimes you need a quick command to get it done once. You can add the-a parameter to commit. The add command is automatically run before commit.
You can also use add to mark files that have been resolved.
11.Agent admitted failure to sign using the key
A strange problem occurs. When you add a user, all the steps are correct, that is, you always need to enter the password. Of course, there is an error message:
Agent admitted failure to sign using the key
To import the private key on the client, run the following command:
Ssh-add ~ /. Ssh/id_rsa
The reason is unknown. The principle of the SSH authentication mechanism is not clear enough now.
12. Clone from the local repository directly
In ubuntu, after the server is set up according to the above operations, the default git file is stored in the/home/git/repositories directory. Run the following command to clone the file.
Git clone/home/git/repositories/CRF. Git