Build a private git server under CentOS

In daily project development, we can use github for code hosting in a fool-like manner, and then carry out collaborative development of the team. But many times the code we develop is not open source (especially when it comes to the company's business). At this time, deploying git on the server can solve this problem well-not only to ensure team development, but also to achieve closed source Code hosting. This article will take CentOS as an example to record the specific steps of deploying a git server under CentOS

Service-Terminal:

Step 1: Configure git

1. Install git from yum

yum install -y git  

2. Check the git version:

After the installation is complete, enter on the server side

git --version

You can view the current version number, as shown in the figure below, my git version is 1.8.3.1

 image.png

3. Create a user:

Create a dedicated git user in the server, custom account password

useradd git
passwd  git
#密码:123456

4. Switch users

su git

5. Enter the user's home directory

cd /home/git

6. Create .ssh configuration directory

If there is this folder, skip this step

mkdir .ssh

7. Put the ssh public key accessed by the user

# Enter the .ssh directory and create an authorized_keys file to store the ssh public key accessed by the user

cd /home/git/.ssh
touch authorized_keys

# Set the permissions of the directory and authorized_keys file, do not modify the permission value

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

#Configure the client's private key:

vim /home/git/.ssh/authorized_keys

Step 2: Configure the remote warehouse

2.1 Create an empty warehouse

We choose to create a user directory under the path: cd /home/, and create a git repository under the user directory

cd  /home/git/
mkdir   document
cd document

#Initialize an empty warehouse

git init --bare  document.git

Enter the following command to give permissions to the git user

chown -R git:git document.git

 

At this point, the empty warehouse has been created successfully, and the path of the warehouse is:

/home/git/document/document.git

 

Clone a remote warehouse

git clone [email protected]:/home/git/document/document.git

 

Guess you like

Origin blog.csdn.net/qq_39999478/article/details/107157562