Home System Tutorial LINUX Build a Git server under CentOS

Build a Git server under CentOS

Apr 15, 2024 pm 07:13 PM
linux centos git linux tutorial Red Hat linux system linux command it service linux certification red hat linux linux video

Build a Git server under CentOS

1. First, you need to install Git. You can use the yum source to install it online:
[root@localhost Desktop]# yum install -y git
Copy after login
2. Create a git user to run the git service
adduser git
Copy after login
3. Initialize git repository:

Here we choose /data/git/learngit.git as our git repository

[root@localhost git]# git init --bare learngit.git
Initialized empty Git repository in /data/git/learngit.git/
Copy after login

Executing the above command will create a bare warehouse. The bare warehouse does not have a workspace. Because the Git warehouse on the server is purely for sharing, users are not allowed to log in directly to the server to change the workspace, and the Git warehouse on the server usually All end with .git. Then, change the owner to git:

[root@localhost git]# chown git:git learngit.git
Copy after login
4. Here, the Git server is almost ready.

Next we clone the remote warehouse on the client

Zhu@XXX /E/testgit/8.34
$ git clone git@192.168.8.34:/data/git/learngit.git
Cloning into 'learngit'...
The authenticity of host '192.168.8.34 (192.168.8.34)' can't be established.
RSA key fingerprint is 2b:55:45:e7:4c:29:cc:05:33:78:03:bd:a8:cd:08:9d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.8.34' (RSA) to the list of known hosts.
git@192.168.8.34's password:
Copy after login

Two points to note here: First, when you use Git's clone or push command to connect to GitHub for the first time, you will get a warning:

The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?
Copy after login

This is because Git uses SSH connection, and when the SSH connection first verifies the Key of the GitHub server, you need to confirm whether the fingerprint information of the GitHub Key really comes from the GitHub server. Just enter yes and press Enter. Git will output a warning telling you that the GitHub Key has been added to a trust list on this machine:

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
Copy after login

This warning will only appear once, and there will be no warnings for subsequent operations. If you are really worried about someone impersonating the GitHub server, before entering yes, you can check whether the fingerprint information of GitHub's RSA Key is consistent with that given by the SSH connection. Second, you are prompted to enter a password to clone. Of course, if you know the password, you can type the password to clone, but the more common way is to use the SSH public key to complete the verification.

5. Create SSH Key

First, check if there is a .ssh directory in the user's home directory. If so, then check if there are two files, id_rsa and id_rsa.pub, in this directory. If they already exist, you can jump directly to the next step. .

If not, open Shell (open Git Bash under Windows) and create SSH Key:

$ ssh-keygen -t rsa -C "youremail@example.com"
Copy after login

You need to change the email address to your own email address, then press Enter all the way, and use the default value. Since this Key is not used for military purposes, there is no need to set a password. If everything goes well, you can find the .ssh directory in the user's home directory. There are two files, id_rsa and id_rsa.pub. These two are the SSH Key pair. id_rsa is the private key and cannot be leaked. id_rsa.pub It is a public key and can be shared with anyone with confidence.

6. Turn on RSA authentication on the Git server

Then you can add your public key to the Git server to verify your information.

On the Git server, you first need to turn on RSA authentication in /etc/ssh/sshd_config, that is:

1.RSAAuthentication yes
2.PubkeyAuthentication yes
3.AuthorizedKeysFile .ssh/authorized_keys
Copy after login

Here we can see that the public key is stored in the .ssh/authorized_keys file. So we create the .ssh directory under /home/git, then create the authorized_keys file and import the newly generated public key into it. Then when you clone again, or when you push later, you don’t need to enter the password again:

Zhu@XXX/E/testgit/8.34
$ git clone git@192.168.8.34:/data/git/learngit.git
Cloning into 'learngit'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
Copy after login
7. Disable shell login for git users

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

git:x:1001:1001:,,,:/home/git:/bin/bash
Copy after login

After the last colon, change it to:

git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
Copy after login

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

The above is the detailed content of Build a Git server under CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

How to open web.xml How to open web.xml Apr 03, 2025 am 06:51 AM

To open a web.xml file, you can use the following methods: Use a text editor (such as Notepad or TextEdit) to edit commands using an integrated development environment (such as Eclipse or NetBeans) (Windows: notepad web.xml; Mac/Linux: open -a TextEdit web.xml)

Can the Python interpreter be deleted in Linux system? Can the Python interpreter be deleted in Linux system? Apr 02, 2025 am 07:00 AM

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

What is the Linux best used for? What is the Linux best used for? Apr 03, 2025 am 12:11 AM

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

How is Debian Hadoop compatibility How is Debian Hadoop compatibility Apr 02, 2025 am 08:42 AM

DebianLinux is known for its stability and security and is widely used in server, development and desktop environments. While there is currently a lack of official instructions on direct compatibility with Debian and Hadoop, this article will guide you on how to deploy Hadoop on your Debian system. Debian system requirements: Before starting Hadoop configuration, please make sure that your Debian system meets the minimum operating requirements of Hadoop, which includes installing the necessary Java Runtime Environment (JRE) and Hadoop packages. Hadoop deployment steps: Download and unzip Hadoop: Download the Hadoop version you need from the official ApacheHadoop website and solve it

Is Debian Strings compatible with multiple browsers Is Debian Strings compatible with multiple browsers Apr 02, 2025 am 08:30 AM

"DebianStrings" is not a standard term, and its specific meaning is still unclear. This article cannot directly comment on its browser compatibility. However, if "DebianStrings" refers to a web application running on a Debian system, its browser compatibility depends on the technical architecture of the application itself. Most modern web applications are committed to cross-browser compatibility. This relies on following web standards and using well-compatible front-end technologies (such as HTML, CSS, JavaScript) and back-end technologies (such as PHP, Python, Node.js, etc.). To ensure that the application is compatible with multiple browsers, developers often need to conduct cross-browser testing and use responsiveness

Do I need to install an Oracle client when connecting to an Oracle database using Go? Do I need to install an Oracle client when connecting to an Oracle database using Go? Apr 02, 2025 pm 03:48 PM

Do I need to install an Oracle client when connecting to an Oracle database using Go? When developing in Go, connecting to Oracle databases is a common requirement...

See all articles