Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Time:2020-10-29

Server side:

1. Install Git

1.1 install git from yum

yum –y install git

1.2 verify that the installation is successful

git --version

If the current version number is displayed, the installation is successful

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

2. Create git’s exclusive management account and password

2.1 create git account

adduser git

2.2 set the password of GIT account

passwd git

Enter the password twice in succession

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Check whether the GIT account is created successfully

cd /home && ls -al

If there is git, the installation is successful

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

3. Create test git warehouse

  1. Switch to git account
    su git
  2. Enter the user home directory of GIT account
    cd /home/git
  3. Create in user home directorytest.gitFolder for warehouse
    mkdir test.git  && cd test.git
  4. staytest.gitInitialization in directorygitWarehouse
    git init --bare
  • amonggit init --bareIt is to create a bare warehouse in the current directory, that is to say, for files without workspace, the files hidden in Git warehouse are directly placed in the current directory. This directory is only used to store the historical version and other data of the warehouse.

  • The path of the warehouse is:/home/git/test.git

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

4. Configure account password free login

4.1 create the default directory of SSH

  1. Enter the home directory of GIT account
    cd /home/git
  2. establish.sshIf this folder already exists, ignore this step
    mkdir .ssh

4.2 create configuration file for verifying public key

  1. get into.sshDirectory and createauthorized_keysFile, this file stores the client remote accesssshPublic key of

    cd /home/git/.ssh
    touch authorized_keys
  2. Set permissions

    chmod 700 /home/git/.ssh/
    chmod 600 /home/git/.ssh/authorized_keys

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

5. Turn on RSA authentication

CentOS 7.4 or above, please skip

  1. Switch back torootuser
    su root

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. get into/etc/sshTable of contents, editingsshd_config
    cd  /etc/ssh
    vi ssh_config

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. PressiEnter insert mode and open the comments for the following three configurations (with#For comments), pressESCTo exit insert mode, press:wqpreservation
    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile .ssh/authorized_keys
    1. It can be done throughvimRegular search for fast location in named mode:/RSAA

Restart the sshd service after saving

systemctl restart sshd

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. CentOS 7.4 discards rsaauthentication support:https://ashub.cn/articles/21
  2. How to configure SSH in Linux system_ Centos7 SSH connection configuration: security configuration under centos7:http://www.linuxdown.net/install/config/20…
  3. Centos7.4 configure SSH login password and key authentication pit:https://www.cnblogs.com/Leroscox/p/9627809…

6. Disable client shell login

IfgitThe client can directly access theshellusegitIt’s not secure to log in to the server remotely

  1. stay/home/gitCreategit-shell-commandsDirectory, and set the owner of the directory togitAccounts. It can be used directlygitAccount login server terminal operation
    su git
    mkdir /home/git/git-shell-commands
  2. modify/etc/passwdfile
    su root
    vim /etc/passwd

    It can be done throughvimThe regular search for fast positioning to this line:/git:x

Find the following figure, where1000It could be something else

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

take

git:x:1000:1000::/home/git:/bin/bash

Change to

git:x:1000:1000::/home/git:/bin/git-shell

Possible shortcut keys:

  1. It’s better not to change it directly. You can copy a line, comment out a line, modify a line, and keep the original
  2. VIM shortcut key: in command mode:yyCopy line,ppaste0Cursor to the beginning of the line$end xDelete a characteriEnter insert mode
  3. Exit to save after modification:escEnter command mode and enter::wq!Save exit.

The server configuration is now complete

client:

1. Client configuration under the same host as the server

1.1 install Git

Because it is placed under the same host as the server, it has been installed when installing the server

1.2 client configuration

  1. Set user name and mailbox
    git config --global user.name "client_username"
    git config --global user.email "[email protected]"
  2. Check whether SSH keys exist
    cd ~/.ssh

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. establishssh keys
    ssh-keygen -t rsa -C "[email protected]"

    Press enter directly when you need to input. The result is as follows

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. Copy generated files togitUnder the table of contents
    cp /root/.ssh/id_rsa.pub /home/git/.ssh/test.pub
  2. taketest.pubThe contents of the file are appended toauthorized_keysin
    cat test.pub >> authorized_keys

1.3 clone repository

  1. Create local folder
    mkdir test_project && cd test_project
  2. Clone remote warehouse
    git clone  [email protected] Address: Home / Git/ test.git

    At this time, you will be prompted that the cloned warehouse is empty. Now the warehouse is empty, so no error is reported

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

lsCheck whether the directory existstestFolder, if it exists, indicates that the clone is successful

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

2. Remote client configuration (Windows 10)

2.1 install git tools for windows

  1. double-clickGit-2.14.0-64-bit.exefunction

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. Select installation directory

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. clickNext

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. clickNext

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. clickNext

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. clickNext

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. clickNext

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

8. ClickNext

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

9. ClickNext

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

10. ClickInstall

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Wait for the installation to complete

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Right click on the desktop if the

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

The installation is successful

2.2 client configuration

  1. Set user name and mailbox
    git config --global user.name "client_username"
    git config --global user.email "[email protected]"
  2. Check if you already have the SSH public key and private key

    Enter the directoryC: Your user nameSee if there is one.sshFolder, are there two files under this folder

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. If not, usessh-keygenestablishsshPrivate key of

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Right click on the desktop and selectGit Bash Here

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. establishssh keys
    ssh-keygen -t rsa -C "[email protected]"

    Press enter directly when you need to input. The result is as follows

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. Manually add the public key to the server. First findC: Your user name. SSH / ID_ rsa.pubThe directory where this file is located
  2. Open in current directoryGit Bash Here

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. Put the localid_rsa.pubFile copy togitThe server
    scp ./id_ rsa.pub  Root @ your IP address / home / git /. SSH/ test.pub

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Because the above steps are forbiddengitclientshellLog in, so you can only userootAccount copy file

  1. Log in to the server and find the one uploaded in the previous steptest.pubFile, directory is/home/git/.ssh/

    9test.pubThe contents of the file are appended toauthorized_keysin
    cat test.pub >> authorized_keys

    2.3 clone repository

  2. Create local folder
    mkdir test_project && cd test_project
  3. Clone remote warehouse
    git clone  [email protected] Address: Home / Git/ test.git

    At this time, you will be prompted that the cloned warehouse is empty. Now the warehouse is empty, so no error is reported

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

lsCheck whether the directory existstestFolder, if it exists, indicates that the clone is successful

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Pull side server and local test

  1. Cloned in the previous steptestCreate a new file in the foldertest.txt

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

  1. Open in current directoryGit Bash Here
    git status
    git add -A;
    git commit -m'test add'
    git push origin master

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

If the above prompt appears, the local submission is successful

  1. Switch to the server and enter1.3Under the folder created in the step (please enter the directory according to the actual situation)
    cd /test_project/test
    git pull

Construction and basic use of GIT server in Linux environment (CentOS 7 version)

If the above prompt appears, the update is successful

epilogue

So far, the wholeGitThe deployment and use of the service are all set up. The functions represented by the commands used in the deployment process should be self Baidu and will not be explained one by one

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint


www.haowuliaoa.com

Recommended Today

Docker minimalist Guide

What is docker? Beginners can use the concept of “virtual machine” to understand docker. When we want to build a virtual machine, we need to download two things: virtual machine software (such as VMware) and. ISO file (such as Ubuntu), and then we can use the Ubuntu system in VMware. Similarly, when we want to […]