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 on CentOS

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

Share

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

In this article, the editor introduces in detail "how to build a Git server on CentOS". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to build a Git server on CentOS" can help you solve your doubts.

Confirm whether git is installed on the server

[root@iz25r8k6ifuz git] # rpm-qa gitgit-1.7.1-3.el6_4.1.x86_64

It has also been installed here, if it is not installed, you can install it with yum install git.

Second, create git users

Here you can choose to create a new user to test, or you can directly use your root to do the following. The author is also looking at the information step by step, here to create a new user teslachen to operate.

[root@iz25r8k6ifuz ~] # useradd tesla [root@iz25r8k6ifuz ~] # passwd tesla

Change the password of user tesla.

New password:

Invalid password: it does not contain enough different characters

Invalid password: too simple

Re-enter the new password:

Passwd: all authentication tokens have been successfully updated.

Note 1: if the user permission to create is not enough, please add sudo

Note 2: there will be a prompt if setting the user's password is too simple, but it can still be set successfully.

Generate ssh public key

Many git servers use the ssh public key for authentication. In order to provide a ssh public key to the git server, if a system user does not already have a key, one must be generated for it in advance.

Linux can run ssh-keygen-t rsa locally to generate keys and copy .pub files to the server.

[root@iz25r8k6ifuz ~] # su tesla [tesla@iz25r8k6ifuz root] $cd ~ [tesla@iz25r8k6ifuz ~] $mkdir .ssh [tesla@iz25r8k6ifuz ~] $ssh-keygen-t rsagenerating public/private rsa key pair.enter file in which to save the key (/ home/tesla/.ssh/id_rsa): enter passphrase (empty for no passphrase): enter same passphrase again:your identification has been saved in / home/tesla/.ssh/id_rsa.your public key has been saved in / home/tesla/.ssh/id_rsa .pub.the key fingerprint is:13:bf:75:ba:67:7f:0e:a0:47:7a:fe:25:bc:81:85:c3 tesla@iz25r8k6ifuzthe key's randomart image is:+-- [rsa 2048]-+ |. | | o. . | | s. E o | |. O | | + = =. | + .o. | | otakoo+ | +-+ [tesla@iz25r8k6ifuz ~] $cd .ssh / [tesla@iz25r8k6ifuz .ssh] $cat id_rsa.pub > > ~ / .ssh/authorized_keysexit

Add tesla to the sudoers file

The tesla user now does not have permission to operate on some folders. Modify the / etc/sudoers file to change his permissions. The top administrator user opens it with the following command.

[root@iz25r8k6ifuz ~] # visudo

Then we find the following line in vim

Root all= (all) all

Press the I key to start the insert, enter and add on the following line

Tesla all= (all) all

Then press the ESC key, enter: wq, enter and save exit

5. Create a git code repository

[root@iz25r8k6ifuz ~] # mkdir / teslarepo [root@iz25r8k6ifuz ~] # cd / teslarepo/ [root@iz25r8k6ifuz teslarepo] # sudo mkdir teslaproject.git [root@iz25r8k6ifuz teslarepo] # chown tesla:tesla / teslarepo/ [root@iz25r8k6ifuz teslarepo] # chown-r tesla:git / teslarepo/ [root@iz25r8k6ifuz teslarepo] # cd teslaproject.git/ [root@iz25r8k6ifuz teslaproject.git] # sudo git-bare initinitialized empty git repository in / teslarepo/teslaproject.git/

Such a git warehouse called teslaproject has been created.

6. Use of local testing

You can test locally on the server, or you can test it directly on your computer. Below I use my own mbp to do the test.

Localhost:~ okay$ cd desktop/git/localhost:git okay$ mkdir teslarepolocalhost:git okay$ cd teslarepo/localhost:teslarepo okay$ git initinitialized empty git repository in / users/okay/desktop/git/teslarepo/.git/localhost:teslarepo okay$ git remote add origin tesla@123.57.159.74:/teslarepo/teslaproject.git

The above command creates a folder locally and adds a remote repository on the server

Localhost:teslarepo okay$ touch a.txtlocalhost:teslarepo okay$ git add a.txtlocalhost:teslarepo okay$ git commit-m "init commit" [master (root-commit) d14cd3b] init commit 1 file changed, 0 insertions (+), 0 deletions (-) create mode 100644 a.txt

The above command creates an a.txt locally and submits it once

Localhost:teslarepo okay$ git push origin mastertesla@123.57.159.74's password:counting objects: 3, done.writing objects: 100,202 bytes | 0 bytes/s, done.total 3 (delta 0), reused 0 (delta 0) to tesla@123.57.159.74:/teslarepo/teslaproject.git * [new branch] master-> master

The above command push the local code to the remote server. Let's check the local clone at once to see if it is correct.

7 Local clone

Localhost:git okay$ mkdir tttlocalhost:git okay$ cd tttlocalhost:ttt okay$ git clone tesla@123.57.159.74:/teslarepo/teslaproject.gitcloning into 'teslaproject'...tesla@123.57.159.74's password:remote: counting objects: 3, done.remote: total 3 (delta 0), reused 0 (delta 0) receiving objects: 100% (3amp 3), done.checking connectivity... Done.

Clone is done. Let's take a look at the folder directory.

The a.txt file from push to the server has been downloaded by clone.

-dividing line-

1. View system user groups

-d: specifies the delimiter of the field. The default field delimiter is "tab"

-f: displays the contents of the specified field

Cut-d:-F1 / etc/group

two。 View system users

Cut-d:-F1 / etc/passwd

3. Clone warehouse

Git clone git@your_gitserver_ip:/home/gitrepo/sample.git

4. Push already has a warehouse

/ / demonstrate git checkout mastergit remote rm origingit remote add origingit @ your_gitserver_ip:/home/gitrepo/sample.gitgit push-u origin master with master branch. This article "how to build a Git server on CentOS" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it. If you want to know more about related articles, please follow the industry information channel.

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