Setup Git Server on Ubuntu 20.04 - Step by Step process ?

When working with the Git version control system, you have many choices such as Github, Bitbucket, or Gitlab. If you want to avoid depending on third-party providers, you can run your own Git server.

Setting up a Git server by yourself allows you to no longer be restricted by public provider's free plans such as maximum repository size, creating unlimited private repositories, and so on.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Linux related queries and Configurations.

In this context, we shall look into how to set up a Git server on your Ubuntu 20.04 machine.


How to install Git Server on Ubuntu ?

To begin with this installation, you need to update your packages list by running:

$ sudo apt update

To install Git, run the following command:

$ sudo apt install git

Verify that Git was successfully installed on your system:

$ git version

It's highly recommended that you should create a new Linux user for managing the Git repositories, run:

$ sudo useradd -m -r -U -d /home/git-repos git

The home directory of git user is located at /home/git-repos

To increase security, we'll create an ssh key to log in to the git user.

Switch to the log-in session of git user by running:

$ sudo su - git

To create the SSH directory and file for holding the authorized ssh key for git user, run the following commands:

$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$ touch ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys

Once, the server was successfully set-up, it’s time to create a new git repository:

$ git init --bare ~/linuxapt.git


How to configure Git repository on Ubuntu ?

Here, you have to add your local user's public SSH key to the authorized_keys file of the git user.

If you already have generated an SSH key for your local user, you can skip the following step:

$ ssh-keygen -t rsa

Now, you can retrieve your public SSH key by running:

$ cat .ssh/id_rsa.pub

This command will display the public SSH key.

So, Copy the above public SSH key then paste it into the authorized_keys file of the git user.


On your local Ubuntu 20.04 machine, assuming that you already had an unversioned directory, for example, ~/go. Change the current directory to it:

$ cd ~/go
$ git init

Next, you have to add a git remote to track your local repository on Git server:

$ git remote add origin git@git-server-ip-address:linuxapt.git

Verify that your Git server was successfully installed and configured, run the following command:

$ cd ~/go
$ touch README
$ git add .
$ git commit -m "Add file Readme"
$ git push origin master


[Need urgent assistance in fixing missing packages on Ubuntu Linux Server? We are here to help you. ]

This article covers how to install and configure a Git server on Ubuntu. Git is basically a Version control system which allows you to keep track of your software at the source level. With Git, You can easily track changes, revert to previous stages, and branch to create alternate versions of files and directories.


To install Git on Ubuntu Server:

1. Run the following commands as sudo user:

$ sudo apt update && sudo apt install git

2. To install the git package on CentOS servers type:

$ sudo yum install git

3. Next, create a new user that will manage the Git repositories:

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

The user home directory is set to /home/git

All the repositories will be stored under this directory.

Related Posts