Git server is not but the SSH server and the same Git app used on the client-side.

It is strongly recommended to use SSH-Keys while using SSH especially if it is protecting the source codes of the company.

If you have any doubt read the post Setting Up SSH Keys [Link].

Preparing the environment:

sudo apt update && sudo apt upgrade -y
sudo apt install git -y
sudo adduser git

Change to the new account:

su git
cd ~
mkdir .ssh
touch .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

Copy the public keys (/home/user1/.ssh/id_rsa.pub) from all the users that will be allowed to work with the repositories to the file /home/git/.ssh/authorized_keys each one in a different line.

At this point follow the post to Increasing Security with Fail2Ban [Link] to protect the SSH against password brute force attacks.

Create the repositories inside the server:

ssh git@server
git init --bare repository1.git
exit

Clone the remote repository to local:

git clone git@server:repository1.git

Create a file and pull it to the server:

touch README.md
git add .
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git commit -m "First Pull"
git push origin master

The lines in gray will only be used on the very first time.

Read more about Working with GitHub Repositories [Link].

One Reply to “Private Git Server on Ubuntu 20.04”

Comments are closed.