Tutorial Install and run Git Server on Linux VPS

Tutorial Install and run Git Server on Linux VPS

Git Server can be used as an open-source and cost-effective solution for programming and development teams simply by providing a virtual VPS server. Preventing Conflict in files, Version control, central management, and Git Server are some of the benefits. In this article, we are going to teach you How to Install and run Git Server on Linux VPS. It should be noted that if you want to buy a Linux VPS server, you can see the packages available in Eldernode.

How to Install and run Git Server on Linux VPS

Recommended Article: How to Find MySQL PHP and Apache Configuration Files

Introduction to Git Server

Git Server has Version Control capability. This feature allows you to always see the change history on each file. Git Server documentation and logs allow you to see what changes were made by each person in each file at what time. Version control is one of the reasons Git Server is so popular with project managers.

Git stores all the main project files on the main server. For each member of the team who intends to edit one of the files, a temporary copy of the file (Working copy) is downloaded in his system and after the work, the changes are applied to the Commit server. It should be noted that Git is also able to detect interference in a file between team members.

Programming and development teams of 2 to 20 people can easily setup their Git server using a virtual server. By doing so, it is enough to make a backup of the virtual server information. In this way, the information security of the project will always be ensured.

Note that Git Server is able to approve and supervise any changes made by team members before publication and final implementation. Each team member submits the changes to the Git server for review. Git notifies the project manager via email or SMS of new changes. If approved, the project manager will approve the changes and the Git server will publish them in the project.

Install and Setup Git Server on Linux VPS

Setting up a Git server allows you to create private repositories without the limitations of free provider applications. In this section, we will explain how to install and setup a Git server on a Linux VPS server.

The first step is to connect to your Linux VPS server using the PuTTY Terminal client. To do this, after completing the fields related to Host Name, Port, and Connection Type, click on Connect.


connect to linux vps


Next, when the SSH connection is opened, you should see a terminal request asking for your username. Now you need to enter your root server username as “root”. Next, enter your password. You can find it on the customer portal. After entering it, press “Enter“.

It’s time to install Git on the server. It should be noted that if you are using Debian or Ubuntu, by running the following commands as a Sudo user, you can refresh the local packet profile and install git:

sudo apt update
sudo apt install git

You can also use the following command to install the git package on CentOS servers:

sudo yum install git

Next, you can create a new user to manage Git repositories:

sudo useradd -r -m -U -d /home/git -s /bin/bash git

It should be noted that the user home directory is set to /home/git. It is also important to know that all repositories are stored in this list. Note that since we did not set a password for the “git” user, logging in will only be possible using the ssh keys.

In the next step you can go to the “git” user using the following command:

sudo su - git

You can then create the SSH directory by running the following command and set the permissions correctly:

mkdir -p ~/.ssh && chmod 0700 ~/.ssh

Then you should create a file named ~/.ssh/authorized_keys which will hold the authorized users’ SSH keys:

touch ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys

You are now ready to create your first Git repository. You need to run the following command to start a new empty repository:

git init --bare ~/projectname.git

Finally, you can name the list to your liking.

How to configure Git Server on Linux VPS

After installing Git Server in the previous section, we now want to discuss how to configure it in this section. It should be noted that in order to be able to push local git changes to the Git server, you must add your local user’s SSH key to the remote “git” user’s authorized_keys file. Note that if you already have a pair of SSH keys in your local system, you can display the public key using the following command:

cat ~/.ssh/

Note: If you get an error message saying “No such file or directory“, it means that you do not have an SSH key pair generated on your local machine.

Based on this, you can use the following command to generate a new  SSH keys pair:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

After executing the above command, you need to copy its output and return it to the Git server console. On the server, open your text editor and paste the public key that you copied from your local machine into the ~/.ssh/authorized_keys file:

sudo nano /home/git/.ssh/authorized_keys

It should note that If you have an existing unversioned project, navigate to the project directory. Now you can create the project directory, and navigate to it If you are starting from scratch:

cd /path/to/local/project

In this step, you should Initialize a git repository:

git init .

Finally, you should add the git remote to your local repository using the following command:

git remote add origin [email protected]_server_ip:projectname.git

Note: In the above command, you must replace git_server_ip with the hostname or IP address of the Git server.

How to Verify the Correct Git Server Setup

In this section, you can check that everything is setup correctly. To do this, create a test file by running the following command:

touch test_file

Then you have to add the changes in the staging area using the following command:

git add .

Now you need to Commit the commands with the help of the following command:

git commit -m "descriptive message"

In the next step, you should push the local repository changes to a remote repository:

git push -u origin master

To add a new collaborator, you can just copy its public SSH key to the “git” user’s ~/.ssh/authorized_keys file.

Recommended Article: How To Install Zpanel On Ubuntu 20.04 & 19.10


Git Server is able to approve and supervise any changes made by team members before publication and final implementation and approval and supervision of the project manager. In this article, we tried to introduce you to Git Server in the first step. Then we taught you to Install and Setup Git Server on Linux VPS. Finally, we explained how to configure and test it.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave Your Comment

Your email address will not be published.

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way


7 days a week, 24 hours a day