Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build Git server under CentOS system

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to build a Git server under the CentOS system". In the daily operation, I believe many people have doubts about how to build the Git server under the CentOS system. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to build the Git server under the CentOS system. Next, please follow the editor to study!

1. Install git

First confirm whether the server has git installed

Enter the command in xshell: $rpm-qa git

The result is as follows:

Install git if not installed

Enter: $yum install git in xshell

two。 Create a git user to run the git service:

Enter: $sudo adduser git in xshell

At this point, add a folder git under the root directory of Ali CVM: / home folder

Create a file at this level to store the public key of the client user: / home/git/.ssh/authorized_keys

In the git bash of the local client, use the command:

$ssh-keygen-t rsa-c "youremail@example.com"

Or

$ssh-keygen

The command generates the public key. By default, the id_rsa.pub file is the public key in disk c: user / .ssh. Just open, copy and paste it into the server's / home/git/.ssh/authorized_keys file with notepad.

3. Establish a git warehouse in the server

Create a git folder dedicated to storing the warehouse in the server root directory.

Create and initialize the warehouse with the following code, this time as an empty warehouse:

$sudo chown-r git:git sample.git

The next step of the code must be executed once, perhaps to obtain push permissions and prevent users from modifying the workspace, and cannot be pushed locally to the git server if it is not executed:

$sudo chown-r git:git sample.git

4. Prohibit git users from logging in to shell

For security reasons, the created git user is not allowed to log in to shell, which can be done by editing the / etc/passwd file. Find a line similar to the following:

Git:x:1001:1001:,:/home/git:/bin/bash

Change to:

Git:x:1001:1001:,:/home/git:/usr/bin/git-shell

In this way, git users can normally use git through ssh, but cannot log in to shell because the git-shell we specified for git users automatically logs out each time they log in.

5. Clone the sample.git repository established on the git server

Navigate to a folder where the clone files are stored in the local git bash, and enter the following clone command:

$git clone git@xxx.xxx.xxx.xxx:/xxx/git/sample.git

The format of the clone server repository command is:

Git clone git@ server public network ip: the path where the warehouse is stored on the server

6. Associate the local git repository with the git server repository

Create and initialize a new sample repository locally, with the same name as the one on the git server.

The repository established on the git server is sample.git, and the local one does not need .git.

Both the server and the local warehouse are available, and the two are associated by the following steps:

Navigate to the local warehouse in the local git bash, enter and execute the following code:

$git remote add sample git@xxx.xxx.xxx.xxx:/xxx/git/sample.git

Enter: $git remote-v in git bash to view the remote git repository associated with the local git repository.

Enter: $git push-u sample master to push the local warehouse master branch to the remote git warehouse in git bash, and-u is required for the first push.

Later push can be directly used in git bash input: $git push sample master.

At this point, the study on "how to build a Git server under the CentOS system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report