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

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article focuses on "how to build git on linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to build git on linux.

Methods: 1, use "yum install git" command to install git;2, use "adduser git" command to create git user; 3, use "ssh-keygen-t rsa" command to create public key; 4, use "git init-- bare" command to initialize git warehouse.

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to build git on linux

1. Install git

First install git, generally speaking, the server now has a built-in git installation package, we only need to execute a simple installation command to install. For example:

$yum install git # centos$ apt-get install git # ubuntu

The above is directly using root login server to operate, but also for the convenience of demonstration.

Git is different from mysql. When mysql is installed, we have to install mysql-server, that is, mysql server. Git is distributed. Every computer that installs git is both a client and a server. Git and git can communicate with each other. In fact, our so-called git server is not essentially different from our own computers. However, we all adopt a centralized management approach in order to manage the project more effectively, so we create a "git server" as the final terminal for everyone else to submit the code.

two。 Create git users and permissions

Of course, we are not allowed to use root directly for communication interaction, so we create a git user as the user who submits the code in the future.

$adduser git

After executing this command, you find that there is an extra git directory in the / home directory. In theory, you now have this git user in your system, and the home directory is in / home/git. However, we do not want this user to connect to the server through ssh, so we want to prohibit this user from using ssh connection to operate. We deal with this by editing a permissions file:

$vi / etc/passwd

Find something similar to

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

The / bin/bash at the end is the permission to allow the ssh connection operation. We change it to / user/bin/git-shell, and the result is as follows:

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

Handled in this way, git will not be able to connect to ssh (in fact, it can, but it will flicker).

We also have to assign a password to git to execute:

$passwd git 123456 (your password)

This password is used when you submit the code later.

3. Public key

This is a special step in git. When communicating, the client and the server need a certificate for verification. First generate a public key:

$cd ~ $ssh-keygen-t rsa

Then you have a public key on your own computer, but where is it? Under the .ssh directory,. The first folder is hidden, but you can cd it.

$cd .ssh $vi id_rsa.pub

So you can see your public key and copy everything down. Next, let's go back to the server.

$cd / home/git/$ mkdir .ssh $cd .ssh $vi authorized_keys

If it is bare metal, there should be no .ssh directory under the / home/git directory on the server, so we create it ourselves, open (automatically create) authorized_keys, paste in the public key we just copied, ok, save and exit.

4. Initialize a git repository

I'm used to throwing this kind of stuff under / var, so let's create a git directory under / var

$cd / var$ mkdir git$ chown-R git:git git$ chmod 777 git$ cd git

Next, we initialize a warehouse with the git command:

$git init-bare arepoforyourproject.git

After initialization, the empty warehouse is OK.

Note: the .git directory must have read and write permissions, because when we are in push, we use git users to push to the server, there will be a write process, if not given writeable permissions, push will fail.

5. Try cloning.

Try cloning to see if the warehouse can be used:

$git clone git@10.0.0.121:/var/git/arepoforyourproject.git

Then you will be prompted to enter your git password, enter it, and then prompt you to clone a blank version library. This means that the server is already OK.

At this point, I believe you have a deeper understanding of "how to build git on linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Servers

Wechat

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

12
Report