Detailed steps to set up a Git server on CentOS

Foreword

We can publish some public repositories of open source code on GitHub, but for private repositories we need to charge. The company usually builds its own Git server, and I also practice by building it on my own server.

Before we start, let's talk about the server information. Here is Alibaba Cloud's CentOS 6.5 64-bit operating system.

One confirm whether the server is installed with Git

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

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

Two create a git user

Here you can choose to create a new user to test, or you can directly use your root to perform the following operations. The author also looked at the information step by step, here is 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: Please add sudo if you have insufficient permissions to create a user;

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

Three generate ssh public key

Many Git servers use SSH public keys for authentication. In order to provide the SSH public key to the Git server, if a system user does not already have the key, a copy of it must be generated in advance.

Linux can run ssh-keygen -t rsa on this machine to generate a key and copy the .pub file to the server.

[ root@iZ25r8k6ifuZ ~]# su tesla
[ tesla@iZ25r8k6ifuZ root]$ cd ~[tesla@iZ25r8k6ifuZ ~]$ mkdir .ssh
[ tesla@iZ25r8k6ifuZ ~]$ ssh-keygen -t rsa
Generating 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@iZ25r8k6ifuZ
The key's randomart image is:+--[ RSA 2048]----+|||||.||   o ..||  S . E o ||. O ||+==.||+.o.||   o+oo+|+-----------------+[tesla@iZ25r8k6ifuZ ~]$ cd .ssh/[tesla@iZ25r8k6ifuZ .ssh]$ cat id_rsa.pub >>~/.ssh/authorized_keys
exit

Four add tesla to the sudoers file

The tesla user does not have operating permissions on some folders, so he can modify the /etc/sudoers file to change his permissions. The top administrator user opens 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 inserting, press Enter to add in the following line

tesla ALL=(ALL) ALL

Then press the esc key, enter: wq, press Enter to save and exit

Five create a Git code warehouse

[ 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 init
Initialized empty Git repository in/teslaRepo/teslaProject.git/

Such a Git repository called teslaProject is created

Six local test use

You can perform local testing directly on the server, or directly use your computer to test. Below I use my own MBP to test.

localhost:~ okay$ cd Desktop/git/
localhost:git okay$ mkdir teslaRepo
localhost:git okay$ cd teslaRepo/
localhost:teslaRepo okay$ git init
Initialized empty Git repository in/Users/okay/Desktop/git/teslaRepo/.git/
localhost:teslaRepo okay$ git remote add origin [email protected]:/teslaRepo/teslaProject.git

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

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

The above command created a.txt locally and submitted it once locally

localhost:teslaRepo okay$ git push origin master
[email protected]'s password:
Counting objects:3, done.
Writing objects:100%(3/3),202 bytes |0 bytes/s, done.
Total 3(delta 0), reused 0(delta 0)
To [email protected]:/teslaRepo/teslaProject.git
 *[ newbranch]  master -> master

The above command pushes the local code to the remote server, let's clone it locally to see if it is correct

Seven local clone

localhost:git okay$ mkdir ttt
localhost:git okay$ cd ttt
localhost:ttt okay$ git clone [email protected]:/teslaRepo/teslaProject.git
Cloning into 'teslaProject'...
[email protected]'s password:
remote: Counting objects:3, done.
remote: Total 3(delta 0), reused 0(delta 0)
Receiving objects:100%(3/3), done.
Checking connectivity... done.

clone is complete, let us look at the folder directory

The a.txt file previously pushed to the server has been cloned

----Dividing line-----

  1. View system user groups
cut -d:-f1 /etc/group
  1. View system users
cut -d:-f1 /etc/passwd
  1. clone warehouse
git clone git@your_gitServer_ip:/home/gitrepo/sample.git
  1. push existing warehouse
//Demonstrate with master branch
git checkout master
git remote rm origin
git remote add origin git@your_gitServer_ip:/home/gitrepo/sample.git
git push -u origin master

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Detailed steps to set up a Git server on CentOS
How to set up a DNS server on Ubuntu 18.04
How to set up the Nginx server configuration block on CentOS 8
How to set up Shiny Server on Ubuntu 14.04
How to set up SSH keys on CentOS 8
CentOS 8 complete steps to set up automatic updates
Centos8 implementation steps to build a local web server
Detailed steps to install centos on vmware10.0 cracked version
How to upgrade CentOS7 to CentOS8 (detailed steps)
How to set up an Apache virtual host on CentOS 7
How to install Git on CentOS 8
How to set up a Masterless Puppet environment on Ubuntu 14.04
Teach you how to build a Git server on Ubuntu
How to set up a firewall with UFW on Ubuntu 14.04
How to set up a production Elasticsearch cluster on Ubuntu 14.04
How to set static IP on Ubuntu 18.04 Server
Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
Centos7 tutorial to build a master-slave DNS server
How to set up time synchronization on Ubuntu 18.04
How to build a LAMP environment on centos7.2
3 minutes to teach you to build gitea on Centos server
How to configure FTP server with Vsftpd on CentOS 8
CentOS uses Nginx to build a download function server
How to configure FTP server with Vsftpd on CentOS 8
How to set a fixed IP based on Ubuntu 16.04
First try to build a Ceph storage cluster on Centos7
Centos7 set up GitBook environment
How to install and configure Postfix mail server on CentOS8
How to set up vsftpd for anonymous downloads on Ubuntu 16.04
Detailed steps to automatically set the line number in ubuntu16.04
How to set up an Apache virtual host on Ubuntu 16.04
Centos6 set up GitBook environment
How to set up an Apache virtual host on Ubuntu 20.04
How to set up password authentication with Nginx on Ubuntu 14.04
How to set up vsftpd for user directories on Ubuntu 16.04
centos6.9 rabbitmq set up SSL
install virtualbox on centos server
Install Nginx server on CentOS 7
Detailed steps to install and configure k8s cluster in centos 7
Detailed steps to install virtual machines with VMware 15 and use CentOS 8
Centos8 uses Docker to deploy a detailed tutorial for Django projects
Centos8 uses Apache httpd2.4.37 to install web server steps in detail
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
CentOS 7 set up NTP, SSH service
CentOS server initialization setting detailed instructions
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to Update to gcc4.9.x on Centos7
How to install TeamViewer on CentOS 8
CentOS8.1 build Gitlab server detailed tutorial
How to install Perl 5 on CentOS
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
CentOS configuration git server in VirtualBox
How to install Jenkins on CentOS 8
How to install Java on CentOS 8