linux:git
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | linux:git [2023/03/04 14:53] – rlunaro | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Git: create your own git server, but sharing access to all the repositories ====== | ||
+ | |||
+ | |||
+ | ===== Intro ===== | ||
+ | |||
+ | This turorial 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 " | ||
+ | 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/ | ||
+ | ~$ rm public_key_of_first_user.pub # you can remove the public key afterwards if you want | ||
+ | </ | ||
+ | |||
+ | ===== Verification: | ||
+ | |||
+ | Check that you can make a ssh to the remote computer with no password request: | ||
+ | |||
+ | < | ||
+ | rluna@asustao: | ||
+ | The authenticity of host ' | ||
+ | ED25519 key fingerprint is SHA256: | ||
+ | This key is not known by any other names | ||
+ | Are you sure you want to continue connecting (yes/ | ||
+ | Warning: Permanently added ' | ||
+ | |||
+ | The programs included with the Ubuntu system are free software; | ||
+ | the exact distribution terms for each program are described in the | ||
+ | individual files in / | ||
+ | |||
+ | 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 ```/ | ||
+ | to hold the repositories. | ||
+ | |||
+ | As root, do the following: | ||
+ | |||
+ | < | ||
+ | # mkdir / | ||
+ | # 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. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
linux/git.txt · Last modified: 2023/03/04 14:55 by rlunaro