Linux Ubuntu build git server

Source: Internet
Author: User
Tags vps domain purchase root access

Previously described how to build a git repository server on Windows, but the server with more than Linux, because cheap (the same VPS is generally cheaper than Windows Linux), no graphical interface, low-profile VPS can also run Linux, open source free, I feel more flexible, download source is also convenient, mobile phone can ssh remote. Today, we'll show you how to build a git server with Linux and use Gitosis to manage users and user permissions.

System environment

Digitalocean Ubuntu 16.04, full root access.

If you are a student, want to get a remote git server to manage your own code, you can also choose do, and now GitHub has students to collect $50 promo code activity.

Build a git server on Ubuntu software necessary to install a git server

Here are the main git core software, SSH protocol software and Python setuptools:

apt-get update && apt-get -y install git-core openssh-server openssh-client python-setuptools lrzsz
Installing Gitosis managing Users and projects

Gitosis is a set of scripts for managing Authorized_keys files and for implementing simple connection limits, managing read and Write permissions for projects, users, and projects, with the following installation commands:

git clone https://github.com/res0nat0r/gitosis.git && cd gitosis && python setup.py install

The git root directory used by Gitosis is /home/git/repositories, where git is the user that is about to be created. If you want to place the warehouse somewhere else, connect it to the/home/git/repositories with a soft connection.

Create a GIT Administrator account

Create a new user as the administrator of the GIT server:

useradd -m gitpasswd git
Initialize gitosis with administrator public key

This administrator's public key means that your local public key is used to manage this gitosis (default will have gitosis-admin read and write permission), you can copy your native (common machine) SSH key to the server, so as to achieve the purpose of management.

1. Generating the public key on the local machine

ssh-keygen -t rsa

After the build is good, the default storage path for Windows is C:\Users\ user name. ssh\id_rsa.pub.

2. Upload the public key to the server and activate the Gitosis
Copy the public key to a git user, so switch to the GIT user first:

su git

Then use the RZ command to copy the value service directly. (Windows uses Lrzsz to copy files to Linux)

3. Initialize Gitosis
Still under Git users, initialize the gitosis with the public key that you just uploaded:

gitosis-init < /home/git/id_rsa.pub
Create a new project on a git server

After you complete the previous step, your Git server is installed. The relevant information is summarized as follows:

    • The default warehouse address is at/home/git/repositories
    • Git Admin user is the git you just created
    • Gitosis Administrative user rights are implemented through a GIT project, the project address is/home/git/repositories/gitosis-admin.git, the default is that the computer you just uploaded the public key can clone this warehouse

Creating a new project is to create a new, empty Git project under the default warehouse address:

cd /home/git/repositoriesmkdir test.gitcd test.gitgit init --bare

This creates a new project with Test.

In the native clone project

First, you need to clone gitosis to manage user permissions with the computer that uploads the public key:

git clone [email protected]:gitosis-admin.git

Among them, Git is you just new Git administrator, followed by your IP (if you want to use your domain name, Namesilo domain purchase and coupon code, after buying the domain name, directly add a DNS resolution to this IP).

Gitosis-admin includes a Keydir folder and a gitosis.conf file , which is used to hold the user's SSH key, which is used to manage user permissions, for example , I'm now going to read and write test permissions to Zhang San and John Doe's computers:

1. Copy the SSH key from the Zhang San computer and the John Doe computer to the Keydir folder

For example, save the Zhang San public key file as Zhangsan.pub under Keydir (the file name is consistent with the following configuration file), John Doe's public key file is saved as lisi.pub and placed under Keydir.

2. Add the relevant configuration in gitosis.conf

[group test]members = zhangsan lisiwritable = test

So, I created a new group of test, where users have Zhangsan and Lisi, and they have read and write permissions.

At this point, if you want the Harry to have only Read permissions, then change the configuration file to:

[group test]members = zhangsan lisiwritable = test[group test_read]members = wangwureadonly = test

So, Wangwu can only clone or pull, but can not push.

3. Push the changes to the server

At this point, only the local changes are completed, to push the changes to the server to take effect (add, commit, push), and then test the permissions of the repository will be the same as in the configuration file settings.

Summarize

Now that you've completed all the tasks of building a git server on Ubuntu, the next step is to co-develop it with Git's common commands.

Original link: Linux ubuntu build git server

Linux Ubuntu 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.