====== Git: create your own git server, but sharing access to all the repositories ====== ===== Intro ===== This tutorial will show how to create a remote git server but every user you give permissions can contribute to every git project in the server. To create a git server in which every project can see only the projects they have assigned, I suppose there are other solutions, but definitely this solution will not work, because in this tutorial every commit will be made by a generic git user that can read and write in every directory. ===== Set up a git server ===== First, install git on your machine. In my case, because it's an ubuntu, I've run: sudo apt-get install git ===== Create git user ===== I prefer to create a "normal" **git** user instead a system one. If you prefer to create a system user, just add the **--system** option to the command: The **--create-home** option is needed because there we will be storing the public keys of the users of the repository. useradd --create-home --user-group git ===== Enter as git user and add remote public keys ===== ~$ mkdir .ssh ~$ chmod o=,g= .ssh ~$ cd .ssh ~/.ssh$ touch authorized_keys ~/.ssh$ chmod o=,g= authorized_keys ===== Add the keys of the different users of the git repository ===== ~$ cat public_key_of_first_user.pub >> .ssh/authorized_keys ~$ rm public_key_of_first_user.pub # you can remove the public key afterwards if you want ===== Verification: in the first_user computer check that you can log in as git user to the remote computer ===== Check that you can make a ssh to the remote computer with no password request: rluna@asustao:~$ ssh git@192.168.0.21 The authenticity of host '192.168.0.21 (192.168.0.21)' can't be established. ED25519 key fingerprint is SHA256:PvSiThCnDq8pNOXyVgsq5vsXLME6oYIbCs0v5urvcpE. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.0.21' (ED25519) to the list of known hosts. The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. git@ubuntu2004:~$ If this is step succeeds, you can continue. ==== Create a directory for your repositories ==== In the server computer, I've created a ```/var/git``` directory to hold the repositories. As root, do the following: # mkdir /var/git # chown git:git /var/git # chmod g=rx,o= /var/git The permissions are set 750 to allow the git user to do anything inside the directory, and the group members to allow other users to read the contents: this will allow us to create other users that can read this directory by adding them to the group of the git user. ==== Create a repository ==== To create a repository, log in as the git user and make a git init --bare: git$ cd /var/git git$ mkdir repo1.git git$ cd repo1.git git$ git init --bare Congrats! you have created your first repository. The .git extension of the directory is not needed, is just to make the url of the repository more cool.