Linux git Server mix tutorial

Source: Internet
Author: User
Tags mkdir ssh git client ssh server

Example One

First look at the effect:
1. No public key required

2. Only a few of the most commonly used Linux commands can be built

Look at the steps
1. Prepare Linux server, install git (generally default installed)

2. Command-line operation

Useradd git #创建一个git账号

passwd git #设置git账号的密码

Su–git #切换到git账号

CD ~ #转到用户目录

mkdir project name. Git #建立项目git文件夹

The name of the CD project. Git

Git–-bare–share Init #初始化git库

3. Immediately pick up your git client (turtle, Sourcetree can) enter the address in this format git@ip:/path/to/project.git

For example: Git@192.168.1.2:/home/git/yourproject.git

Git pull, you need to enter a password, you can enter the above created a good git account password to

Start using it!

Tips
This approach builds a GIT server that is limited to small teams and projects that are not sensitive to contributing code

Git's own public key is intended to prevent false submissions from being spoofed by someone else's username. But that's a way to get around this.

When you want to open a new Git library, remember to use the GIT account to repeat the above steps, if the folder created using the root level account will encounter insufficient permissions when using the client


Example 2

1, the generation of public key

Any engineer who needs to use a GIT server needs to generate an SSH public key. Can be generated by Ssh-keygen.

~/.ssh$ Ssh-keygen
Generating public/private RSA key pair.
Enter file in which to save the key (/HOME/SHIZHEN/.SSH/ID_RSA):
Enter passphrase (empty for no passphrase):
Enter same Passphrase again:
Your identification has been saved In/home/shizhen/.ssh/id_rsa.
Your public key has been saved in/home/shizhen/.ssh/id_rsa.pub.
The key fingerprint is:
a8:19:49:f4:e6:e8:4f:8f:3e:47:c9:19:4c:09:ee:7f Shizhen@sz-desktop
The key ' s Randomart image is:

First let you enter the location to save the public key, direct return can, and then prompts you to repeat a password two times, if you do not want to use the public key when entering the password, direct return can be. When completed, two file Id_rsa (private key) and id_rsa.pub (public key) are generated in the. SSH directory in the home directory.

The generated public key, Id_rsa.pub, is sent to the manager of the Git warehouse.

2. Erecting server

(1) Server-side
It's a good idea to create a git group so that you can add a git user and add it to the group.

sudo adduser git
Su git
CD ~
mkdir. SSH

Create a new. SSH directory for the Git user, and add the developer's SSH public key to the Authorized_keys file for git, the user. If there are zhangsan,lisi two developers.

Cat/tmp/id_rsa_zhangsan.pub >> ~/.ssh/authorized_keys
Cat/tmp/id_rsa_lisi.pub >> ~/.ssh/authorized_keys

Build an empty Warehouse

CD work
mkdir Project.git
CD Project.git
Git--bare init

Using--bare will initialize a warehouse without any working directory and will not see the project source.
In order not to allow developers to enter the IP address every time the clone code, you can use DNS. The specific operation is as follows

sudo vim/etc/hosts

Add the following line to the inside

192.168.1.100 Gitserver

(2) Developer side

In the absence of a warehouse, you need to create a new warehouse first. The following commands are executed in the directory where the warehouse needs to be established.

CD My_project
Git init
git Add. (Add all files to warehouse management)

git commit-m "initial commit"
Git remote add Origin git@gitserver:/home/git/work/project.git (ie: git@192.168.1.100:/home/git/work/project.git)
Git push Origin Master

If you have a local warehouse, but want to push the code to our new server, you can use the following command
Build the branch code you want to push into the master branch

git checkout-b master xxxxx
Git push Origin Master

Such a simple server can work, other developers can directly from the server for code development.
To protect the GIT server, limit the developer login to the server, you can use the following measures.

sudo vim/etc/passwd

Find this class at the end of the file

git:x:1001:1001:,,,:/home/git:/bin/bash
Change the/bin/bash/to/user/bin/git-shell

Now developers can only push and retrieve code via SSH, and cannot log on to the SSH server.

3. The question

? In the SSH use of the same with the Sam Pepper?? 霈 F??? Interest

Agent admitted failure to sign using the key

Solution? Q Use the ssh-add instruction to add the private key (depending on the individual's key name for different changes id_rsa)
That is, the individual developer executes the command
Ssh-add Id_rsa

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.