Git multi-person collaboration user permission configuration

A series of functions such as git warehouse creation and user configuration have been experienced for a long time.

Recently, it is necessary to configure a git environment for multi-person collaboration (multiple git users).

Some problems were found.

This is the case. The git repository I created on my server before does not have a problem of multi-person collaboration. Just myself, so after the owner of the git repository is configured as the git user I use, there is no permission problem at all.

But when multiple people collaborate, when other people want to modify files from the directory to which your permission belongs, obviously he doesn't have this permission. Of course, you can change the permissions of the git warehouse directory to 777 very rudely, but this is very unreasonable, and this thing treats the symptoms and not the root cause. It is only useful for your previous directories. When you upload new files, new The permission of the generated directory is still 755, so the configuration of this permission may be problematic.

The solution is actually very simple.

1: We add two new users and set passwords, the command is as follows:

adduser yonghu1
adduser yonghu2

2: View all user commands: choose one of three, all works

compgen -u
getent passwd
cat /etc/passwd

3: Add user group git, the command is as follows:

Groupadd git

4: View all user group commands

Cat /etc/group
 

5: Add the two users just created to the git group just created.

usermod [-G] [GroupName1,GroupName2] [UserName]
usermod –G git yonghu1
usermod –G git yonghu2

6: Create a git repository, here is the key point, change the permissions to owner to yonghu1, the owning group is naturally git

git init --bare –shared=group
--bare:裸仓库
--shared:分享选项
--shared[=(false|true|umask|group|all|world|everybody|0xxx)]

When share is specified as true: the access permissions of directories and files in $GIT_DIR can be changed by configuring "core.sharedRepository"

The default share permissions are generated according to umask

Modify directory permissions

Chown –R yonghu1:git /你的仓库地址

7: Forbid git users to log in through ssh

Please move to " Two ways to prohibit git user SSH login "

The above is probably the whole content. If you have good suggestions, please enter your comments below.

Welcome to personal blog
https://guanchao.site

Welcome to the Mini Program:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_39708228/article/details/113032553