Linux Simple build git server

Source: Internet
Author: User
Tags using git

If you have fewer people using git, you can use the following steps to quickly deploy a GIT server environment.

1. Generate the SSH public key

Every engineer who needs to use a GIT server needs to generate an SSH public key
Go to your ~/.ssh directory to see if you have a file name and filename. pub to name a pair of files, this 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 not even the. SSH directory), you can use the Ssh-keygen program to build them, the program is provided by the SSH package in the LINUX/MAC system, and is included in the Msysgit package on Windows:

123456789
$ ssh-keygen generating public/private RSA key pair. Enter file in which to save the key (/USERS/SCHACON/.SSH/ID_RSA): Enter passphrase (empty for no passphrase): Enter same p Assphrase again:your identification has been saved In/users/schacon/.ssh/id_rsa. Your public key have been saved in/users/schacon/.ssh/id_rsa.pub.the key fingerprint is:43:c5:5b:5f:b1:f1:50:43:ad:20:a6 : 92:6a:1f:9a:3a [email protected]

It asks you to confirm where to save the public key (. Ssh/id_rsa), then it will let you repeat a password two times, if you do not want to enter the password when using the public key, you can leave blank.

Now, all users who have done this will have to give their public key to either you or the Git Server Manager (assuming the SSH service is set to use the public key mechanism). They only need to copy the contents of the. pub file and then e-email it. The public key looks roughly like this:

1234567
$ cat ~/.ssh/id_rsa.pub Ssh-rsa aaaab3nzac1yc2eaaaabiwaaaqeakloupkdhrfhy17sbrmtipnltgk9tjom/bwdsugpl+ nafzlhdtyw7hdi4yz5ew18jh4jw9jbhufrviqzm7xlelevf4h9lfx5qvkbpppswg0cda3pbv7kodj/mtyblwxfcr+ hao3fxritbqxix1nkhxphazsmcilq8v6rjsnaqwdsdmfvslvk/7xat3faojoasncm1q9x5+3v0ww68/ eifmb1zuufljqjkprrx88xypndvjynby6vw/pb0rwert/enmz+aw4ozpntpi89zpmvmluayrd2ce86z/il8b+gw3r3+ 1nkatmikjn2so1d01qratlmqvssbxnrrfi9wrf+m7q== [email protected]
2. Server Setup

First, create a ' git ' user and create an. SSH directory for it, under the user's home directory:

1234
$ sudo adduser git$ su git$ cd$ mkdir. SSH

Next, add the developer's SSH public key to the user's Authorized_keys file. Suppose you received several public keys by e-mail to coexist in a temporary file. Just add them to the Authorized_keys file.

123
$ cat/tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys$ cat/tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys$ Cat/tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys

You can now run git init with the –bare option to set an empty repository, which initializes a repository that does not contain a working directory.

1234
$ cd/opt/git$ mkdir project.git$ cd project.git$ git--bare init

At this point, the developer can add it as a remote repository, push a branch, and upload the first version of the project to the repository. It is important to note that each time you add a new project, you need to log in to the host through the shell and create a pure repository. We might as well use gitserver as the hostname of the GIT user and repository. If you are running the host on the network and you set gitserver in DNS to point to that host, the following commands are available:

1234567
# on an engineer's computer $ cd myproject$ git init$ git Add. $ git commit-m ' initial commit ' $ git remote add origin [email protected]:/ opt/git/project.git$ git push Origin master

In this way, the cloning and pushing of other people are just as simple:

1234
$ git clone [email protected]:/opt/git/project.git$ vim readme$ git commit-am ' fix for the README file ' $ Git push origin Master

This method can be very fast for a few developers to set up a read-write Git service.

As an extra precaution, you can use Git's git-shell simple tool to limit the activity of git users to git-only. By setting it as the shell that the git user is logged into, the user cannot have normal shell access to the host. To achieve this, it is necessary to indicate that the user's login shell is Git-shell, not bash or CSH. You may have to edit the/etc/passwd file

1
$ sudo vim/etc/passwd

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

1
Git:x:1000:1000::/home/git:/bin/sh

Change the bin/sh to/usr/bin/git-shell (or view its location with which Git-shell). The line is modified to look like this:

1
Git:x:1000:1000::/home/git:/usr/bin/git-shell

Now git users can only use SSH connections to push and get the Git repository, rather than using the host shell directly. If you try to log in, you will see a rejection message like this:

123
$ SSH [email protected]fatal:what do think I am? A Shell? (What do you think I am?) Shell, huh? ) Connection to Gitserver closed. (The Gitserver connection is disconnected.) )

Linux Simple build git server

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.