在许多帐户中使用没有 Sudo 的 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1367258/
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-19 03:49:02  来源:igfitidea点击:

Using Git without Sudo in many accounts

gitubuntusudo

提问by hhh

How can you use Git without Sudo in multiple accounts in one Ubuntu?

在一个 Ubuntu 中,如何在没有 Sudo 的情况下在多个帐户中使用 Git?

My Ubuntu has many accounts. The creation of new accounts has made Git inaccessible by me without sudo.

我的 Ubuntu 有很多帐户。新帐户的创建使我在没有 sudo 的情况下无法访问 Git。

I changed the owner to be me, masi, and the group to be adminwhere the masibelongs to. I have the following permissions for Git

我改变了所有者是我,马嘶,并且该组将admin马嘶属于。我对 Git 有以下权限

800 -rwxrwxrwx 1 masi admin 813744 2009-02-20 23:01 /usr/bin/git

I get the following message in trying to use Git

我在尝试使用 Git 时收到以下消息

git status
fatal: unable to create '.git/index.lock': Permission denied

I run find . -iregex ".*index.l.*which returns no matches so there seems to be no index.lock in locking the system. I run the same command also with sudo unsuccessfully.

我运行find . -iregex ".*index.l.*它不返回匹配项,因此锁定系统时似乎没有 index.lock 。我也用 sudo 运行相同的命令失败。

回答by J?rn Schou-Rode

If I understand your question correctly, you need grant several *nix user accounts write access to the same git repository. Using the --sharecommand line argument for git initshould enable this. The GitWiki has a few words to say about this. This should do the trick:

如果我正确理解您的问题,您需要授予多个 *nix 用户帐户对同一个 git 存储库的写访问权限。使用--share命令行参数 forgit init应该可以启用此功能。GitWiki 对此有几句话要说。这应该可以解决问题:

git --bare init --shared=all

If you have already created your repository, you might be able to convert it to a "shared repository" by throwing this command:

如果您已经创建了存储库,则可以通过抛出以下命令将其转换为“共享存储库”:

git repo-config core.sharedRepository true

in your repository, as mentioned in a blog post at moserei.de.

在您的存储库中,如moserei.de 的博客文章中所述

2014 update: This is still possible but the command has changed from repo-config to config.

2014 更新:这仍然是可能的,但命令已从 repo-config 更改为 config。

git config core.sharedRepository true

回答by Alan Haggai Alavi

Git is meant to be distributed. So, every user should be having a separate repository of his/her own. The above method contradicts this methodology. Apart from that, I suspect the permissions of the .gitdirectory.

Git 旨在分发。因此,每个用户都应该拥有自己的单独存储库。上述方法与该方法论相矛盾。除此之外,我怀疑.git目录的权限。

回答by Douglas Leeder

I would guess the ownership of the .gitdirectory are the problem.

我猜.git目录的所有权是问题所在。

You shouldn't use one source tree from different users - it's likely to lead to problems.

您不应该使用来自不同用户的一种源代码树 - 这可能会导致问题。

The gitexecutable is not the issue. It should be owned by root, and have 755 permissions. (-rwxr-xr-x)

git可执行文件不是问题。它应该归 root 所有,并且拥有 755 权限。( -rwxr-xr-x)

In other words you can use git from multiple accounts, but you shouldn't share a single working directory.

换句话说,您可以从多个帐户使用 git,但您不应共享一个工作目录。

回答by hillu

Having the permissions of any executable set so that a normal user can overwrite the executable is a considerable security risk. (Try overwriting /usr/bin/gitwith a shell script that calls rm -rf $HOME.)

拥有任何可执行文件的权限以便普通用户可以覆盖可执行文件是一个相当大的安全风险。(尝试/usr/bin/git使用调用 的 shell 脚本覆盖rm -rf $HOME。)

Change the permissions back to 755 and make git owned by root:root again. (Ubuntu's package manager would reset the permissions on the next upgrade anyhow unless you used dpkg-statoverride(8))

将权限改回 755 并再次让 git 归 root:root 所有。(除非您使用 Ubuntu 的软件包管理器,否则无论如何都会重置下一次升级的权限dpkg-statoverride(8)

I agree with those who say that it may not be a good idea to have multiple users share one git repository. If you still think that it is necessary, consider setting up a new group, chgrpthe directory holding the repository and all the files therein to that group andset the setgid bit on the directories. (The --sharedparameter to git initmay do some of this for you, too.) Then, add all the users to the group that should have commit rights.

我同意那些说让多个用户共享一个 git 存储库可能不是一个好主意的人。如果您仍然认为有必要,请考虑设置一个新组,chgrp将保存存储库和其中所有文件的目录放到该组中,并在目录上设置 setgid 位。(--sharedto 参数也git init可以为您做一些事情。)然后,将所有用户添加到应该具有提交权限的组中。

回答by Won Jun Bae

You can verify members using

您可以使用验证成员

members groupname

Then you can set the permission level for the username:groupname pair,

然后您可以为 username:groupname 对设置权限级别,

change the ownership
sudo chown -v -R username:groupname sprout
chmod -R g+w .git/*