Group-level git server Construction

Source: Internet
Author: User
Group-level git server Construction

Reprinted: linuxhttp: // blog. prosight. Me/index. php/2009/11/485

If there are few git users, you can use the following steps to quickly deploy a git server environment.

1. generate an SSH Public Key

Every engineer who needs to use the GIT server needs to generate an SSH Public Key
Enter your own ~ /. Ssh directory. check whether there is a pair of files named after the file name and file name. Pub. The file name is usually id_dsa or id_rsa. The. Pub file is the public key, and the other file is the key. If you do not have these files (or simply connect to them. you can use the ssh-keygen program to create them. The program is provided in the Linux/MAC system by the SSH package, and included in the msysgit package on Windows:

  1.  
  2. $Ssh-keygen
  3. Generating public/private RSA key pair.
  4. EnterFileInWhichTo save the key (/users/schacon /.SSH/Id_rsa ):
  5. Enter passphrase (empty for no passphrase ):
  6. Enter same passphrase again:
  7. Your identification has been saved in/users/schacon /.SSH/Id_rsa.
  8. Your public key has been saved in/users/schacon /.SSH/Id_rsa.pub.
  9. The key fingerprint is:
  10. 43: C5: 5b: 5f: B1: F1: 50: 43: AD: 20: A6: 92: 6a: 1f: 9A: 3A schacon@agadorlaptop.local
  11.  

It requires you to confirm the location of the public key (. Ssh/id_rsa), and then it will let you repeat the password twice. If you do not want to enter the password when using the public key, leave it blank.

Now, all users who have done this step have to give their public keys to you or the GIT server administrator (assuming that the SSH service is set to use the public key mechanism ). They only need to copy the content of the. Pub file and then e-email it. The Public Key is roughly as follows:

  1.  
  2. $Cat~ /.SSH/Id_rsa.pub
  3. Ssh-RSA aaaab3nzac1yc2eaaaabiwaaaqeakloupkdhrfhy17sbrmtipnltgk9tjom/bwdsu
  4. GPL + Signature
  5. Pbv7kodj/mtyblwxfcr + hao3fxritbqxix1nkhxphazsmcilq8v61_snqwdsdmfvslvk/7xa
  6. T3faojoasncm1q9x5 + 3v0ww68/eifmb1zuufljqjkprrx88xypndvjynby6vw/pb0rwert/EN
  7. MZ + aw4ozpntpi89zpmvmluayrd2ce86z/il8b + gw3r3 + 1nkatmikjn2so1d01qratlmqvssbx
  8. Nrrfi9wrf + m7q = schacon@agadorlaptop.local
  9.  
2. Set up servers

First, create a 'git 'user and create a. Ssh directory for it. In the user's main directory:

  1.  
  2. $SudoAdduser git
  3. $SuGit
  4. $ Cd
  5. $Mkdir.SSH
  6.  

Next, add the developer's SSH Public Key to the user's authorized_keys file. Assume that you have received several public keys through e-mail and stored them in temporary files. Add them to the authorized_keys file.

  1.  
  2. $Cat/Tmp/id_rsa.john.pub> ~ /.SSH/Authorized_keys
  3. $Cat/Tmp/id_rsa.josie.pub> ~ /.SSH/Authorized_keys
  4. $Cat/Tmp/id_rsa.jessica.pub> ~ /.SSH/Authorized_keys
  5.  

Now you can use the-bare option to run git init to set an empty repository, which will initialize a repository that does not contain a working directory.

  1.  
  2. $ CD/opt/git
  3. $MkdirProject. Git
  4. $ CD project. Git
  5. $ Git-bare init
  6.  

In this case, developers can add it as a remote repository, push a branch, and upload the project of the first version to the repository. It is worth noting that every time you add a new project, You need to log on to the host through shell and create a pure repository. We may wish to use gitserver as the host name of the GIT user and repository. If you run the host inside the network and set gitserver to point to the host in DNS, the following commands are available:

  1.  
  2. # On an engineer's computer
  3. $ CD myproject
  4. $ Git init
  5. $ Git add.
  6. $ Git commit-m'initial commit'
  7. $ Git remote add origin git @ gitserver:/opt/git/Project. Git
  8. $ Git push origin master
  9.  

In this way, the cloning and pushing of other people become very simple:

  1.  
  2. $ Git clone git @ gitserver:/opt/git/Project. Git
  3. $ Vim readme
  4. $ Git commit-am 'fix for the README file'
  5. $ Git push origin master
  6.  

Using this method, you can quickly set up a readable and writable git service for a few developers.

As an additional precaution, you can use the git-shell tool that comes with git to limit the activity of git users only to git-related. Set it as the shell that the GIT user logs on to, then the user cannot have normal shell access to the host. To achieve this, you need to specify that the user's login shell is Git-shell, rather than bash or CSH. You may have to edit the/etc/passwd file.

  1.  
  2. $SudoVim/etc/Passwd
  3.  

At the end of the file, you should be able to find a line like this:

  1.  
  2. Git: X: 1000: 1000:/home/git:/bin/Sh
  3.  

Change bin/sh to/usr/bin/Git-shell (or use which Git-shell to view its location ). The row is modified as follows:

  1.  
  2. Git: X: 1000: 1000:/home/git:/usr/bin/Git-shell
  3.  

Currently, git users can only use SSH connections to push and obtain git repositories, rather than directly using the host shell. If you try to log on, you will see the following denial information:

  1.  
  2. $SSHGit @ gitserver
  3. Fatal: What do you think I am? A shell? (What do you think I am? Shell ?)
  4. Connection to gitserver closed. (The gitserver connection is disconnected .)

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.