A Git server is simply an SSH server running the same Git application used on the client side.
It is strongly recommended to use SSH keys when using SSH, especially when protecting company source code.
If you have any doubts, 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
Switch 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 users who will be allowed to work with the repositories into the file /home/git/.ssh/authorized_keys, one per line.
At this point, follow the post Increasing Security with Fail2Ban [Link] to protect SSH against brute force attacks.
Create repositories on the server:
ssh git@server git init --bare repository1.git exit
Clone the remote repository locally:
git clone git@server:repository1.git
Create a file and push 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 Push" git push origin master
The lines in gray are only needed the first time.
BONUS
Automate Git operations across multiple repos simultaneously with MyRepos [Link]. For example, pull all of them at once:
sudo apt install myrepos -y cd repositoryDirectory mr register mr run git pull
Read more about Working with GitHub Repositories [Link].