Build a Git server under Linux

Source: Internet
Author: User
Tags git clone

Environment:1.7. 1)
Git (version 2.8.4.windows.1)
① Installing Git

Linux as a server-side system, Windows as a client system, install Git separately

Server-side:

#yum install-y git

When you're done installing, check out the Git version

[[email protected] ~]# git--1.7. 1

Client:

Download Git for Windows, address: https://git-for-windows.github.io/

After installation, you can use Git Bash as the command line client.

When you're done installing, check out the Git version

$ git--2.8. 4. Windows. 1

② server-side create git users to manage GIT services and set passwords for Git users:
[[email protected] home]# ID gitid:git: No this user [[email protected] home]# useradd git[[email protected] home]# passwd git

③ server-side Create Git repository

Set/home/data/git/gittest.git to Git repository

Then change the owner of the Git repository to git.

[Email protected] home]# mkdir-p data/git/--bare data/git/ in/home/data/git/gittest.git/ [email protected] home]# CD data/git/-R git:git gittest.git/

④ Client Clone Remote repository

Enter the Git Bash command line client, create the project address (set at D:/wamp64/www/gittest_gitbash) and enter:

[Email protected] MINGW64/d$ CD wamp64/www[email protected]-pc mingw64/d/wamp64/www$ mkdir gittest_gitbash[email Protected]-pc mingw64/d/wamp64/www$ cd gittest_gitbash[email protected]-pc mingw64/d/wamp64/www/  gittest_gitbash$

Then clone the project from the Linux Git server:

$ git clone [email protected]:/home/data/gittest.git

  

When you first connect to a target Git server, you get a hint:

' 192.168.56.101 (192.168.56.101) ' can't be established.  is sha256:ve6wv/Continue

Select Yes:

' 192.168.56.101 ' (RSA) to the list of known hosts.

At this time C:\Users\ user name \.ssh will be a file known_hosts, and later on this computer to connect to the target Git server again will not prompt the above statement.

You are prompted to enter a password, which can be verified using the SSH public key.

⑤ client creates SSH public and private keys
" [email protected] "

At this time C:\Users\ user name \.ssh will be two more files Id_rsa and id_rsa.pub

Id_rsa is the private key

Id_rsa.pub is the public key

⑥ server-side Git opens RSA authentication

Enter the/etc/ssh directory, edit the Sshd_config, and open the comments for the following three configurations:

rsaauthentication yespubkeyauthentication yesauthorizedkeysfile. SSH/authorized_keys

Save and restart the SSHD service:

[Email protected] ssh]#/etc/rc.d/init.d/sshd restart

The path that the public key is stored by Authorizedkeysfile is. Ssh/authorized_keys, which is actually $Home/.ssh/authorized_keys, because the user who manages the git service is git, so the paths that actually store the public key are /home/git/.ssh/authorized_keys

Create a directory under/home/git/. SSH

[[email protected] git]# pwd/home/git
[[email protected] git]# mkdir. SSH
-
. .. . bash_logout. Bash_profile. bashrc. gnome2. Mozilla SSH

Then change the owner of the. ssh folder to git

[Email protected] git]# Chown-R git:git. Ssh[[email protected] git]# ll-a total dosage +drwx------.5git git4096August -  -:Geneva. DRWXR-xr-x.8Root root4096August -  +: + ..-rw-r--r--.1git git -October -  the. Bash_logout-rw-r--r--.1git git176October -  the. Bash_profile-rw-r--r--.1git git124October -  the. BASHRCDRWXR-xr-x.2git git4096November A  .. GNOME2DRWXR-xr-x.4git git4096May8  A: A. MOZILLADRWXR-xr-x.2git git4096August -  -: ,. SSH

⑦ Importing the client public key to the server-side/home/git/.ssh/authorized_keys file

Go back to Git Bash and import the file:

$ SSH [email protected]192.168. 56.101 ' cat >>. Ssh/authorized_keys ' < ~/.ssh/id_rsa.pub

Need to enter password for server-side git user

Go back to the server and see if the Authorized_keys file exists under. SSH:

4 1 398 August  : Authorized_keys

You can see if it is the client-generated public key.

The essential:

Modify the permissions for the. SSH directory to 700

Modify the permissions for the. ssh/authorized_keys file to 600

the

⑧ Client clone remote repository again
$ git clone [email protected]192.168. 56.101:/home/data/git/gittest.git

To view the client project directory:

The project has been clone.

You can also use the Tortoisegit client to manage projects:

Clone

⑨ disable git user SSH login server

Git users who were previously created on the server do not allow SSH to log on to the server

Edit/etc/passwd

Found it:

GIT:X:502:504::/home/git:/bin/bash

Revision changed to

GIT:X:502:504::/home/git:/bin/git-shell

At this point, git users can use git through ssh, but they can't login to the system via SSH.

Reference: Build your own git server under CentOS

Build a Git server under Linux

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.