在 Ubuntu 上具有多个用户的 Git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/360348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:07:03  来源:igfitidea点击:

Git repository with multiple users on Ubuntu

linuxsecuritygitubunturepository

提问by Espen

I have an existing bare git repository located in /home/myaccount/git/project. I am currently using it over ssh from my local machine without any problems. I want to add a second user on the server which only shall access to this git repository (maybe move the repo outside my account folder?). How? Using latest version of git and ubuntu on slicehost.

我在 /home/myaccount/git/project 中有一个现有的裸 git 存储库。我目前正在本地机器上通过 ssh 使用它,没有任何问题。我想在服务器上添加第二个用户,该用户只能访问此 git 存储库(也许将存储库移到我的帐户文件夹之外?)。如何?在 slicehost 上使用最新版本的 git 和 ubuntu。

I have this setup: user: sleepyhead user: developer1 group: git. both sleepyhead and developer1 are members of this group repository /home/sleepyhead/git/project1

我有这个设置:用户:sleepyhead 用户:developer1 组:git。sleepyhead 和 developer1 都是该组存储库 /home/sleepyhead/git/project1 的成员

I want to: move repository to a proper place, either /home/git/project1 or /usr/local/git/project1. What is recommended? developer1 should permissions to read and write project1 with git. no other permissions should be given.

我想:将存储库移动到适当的位置,/home/git/project1 或 /usr/local/git/project1。推荐什么?developer1 应该具有使用 git 读取和写入 project1 的权限。不应授予其他权限。

I do not know how to properly set the permissions and to restrict developer1 to only have access using git to project1.

我不知道如何正确设置权限并将 developer1 限制为只能使用 git 访问 project1。

回答by orip

Have him create a ssh keypair and send you the public key.

让他创建一个 ssh 密钥对并将公钥发送给您。

Add the public key to your ~/.ssh/authorized_keysfile, and add the command="..."option to limit it to the git-shell - see this linkfor an example.

将公钥添加到您的~/.ssh/authorized_keys文件中,并添加将command="..."其限制到 git-shell的选项 - 请参阅此链接以获取示例。

回答by gregf

Orip's answer is probably all you need. If you want something a little more automated you might want to look at gitosis

Orip 的答案可能就是您所需要的。如果你想要一些更自动化的东西,你可能想看看gitosis

回答by Paul Beckingham

You will also probably want to have both of those users in the same user group, and to make sure you have group-write privileges on the repository.

您可能还希望将这两个用户都放在同一个用户组中,并确保您对存储库具有组写入权限。