Linux Server builds git

Source: Internet
Author: User
Tags git clone

1. Install 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--versiongit version 2.8.4.windows.1

2. Create a git user on the server side to manage the Git service and set a password for the git user

[[email protected] home]# ID gitid:git: No this user [[email protected] home]# useradd git[[email protected] home]# passwd git (to git User to add password, below will ask to enter the password)

3. Create a Git repository on the server side

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/gittest.git[[email protected] home]# git init--bare data/git/gittest.gitinit  ialized empty Git repository In/home/data/git/gittest.git/[[email protected] home]# CD Data/git/[[email protected] git]# Chown-r Git:git gittest.git/

4. Client creates SSH public key and private key

< In another blog I have introduced to >

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

5, server-side Git open 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

Create a directory under/home/git/. SSH

[Email protected] git]# pwd/home/git[[email protected] git]# mkdir. Ssh[[email protected] git]# ls-a. .. . 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 consumption 32drwx------. 5 git git 4096 August 20:04. Drwxr-xr-x. 8 root root 4096 August 28 19:32.. -rw-r--r--. 1 git git 18 October. Bash_logout-rw-r--r--. 1 git git 176 October. Bash_profile-rw-r--r--. 1 git git 124 October bashrcdrwxr-xr-x. 2 git git 4096 November gnome2drwxr-xr-x. 4 git git 4096 May 8 12:22. Mozilladrwxr-xr-x. 2 git git 4096 August 20:08 ssh

6. Import the client public key into the server-side/home/git/.ssh/authorized_keys file

Go back to Git Bash and import the file:

< ~/.ssh /id_rsa.pub

Then you need to enter the password for the server-side git user

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

[[Email protected] git]# CD. Ssh[[email protected]. ssh]# ll total dosage 4-rw-rw-r--. 1 git git 398 August 20:08 Authorized_keys

Important:

Modify the permissions for the. SSH directory to 700

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

[Email protected] git]# chmod ssh[[email protected] git]# CD. Ssh[[email protected]. ssh]# chmod

7. Client Clone remote Repository

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

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

The authenticity of host ' 192.168.1.2 (192.168.56.101) ' can ' t be established. RSA Key fingerprint is sha256:ve6wv/sca059eqouozbfozdfmmh3b259nigfmvdadqq.are your sure you want to continue connecting (ye s/no)?

Select Yes:

warning:permanently added ' 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.

8. 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.

Linux Server builds git

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.