简体   繁体   English

在许多帐户中使用Git without Sudo

[英]Using Git without Sudo in many accounts

How can you use Git without Sudo in multiple accounts in one Ubuntu? 如何在一个Ubuntu中的多个帐户中使用没有Sudo的Git?

My Ubuntu has many accounts. 我的Ubuntu有很多账号。 The creation of new accounts has made Git inaccessible by me without sudo. 新帐户的创建使我无法访问Git,没有sudo。

I changed the owner to be me, masi, and the group to be admin where the masi belongs to. 我将所有者更改为我,masi,并将该组改为masi所属的admin I have the following permissions for Git 我有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.* 我跑了find . -iregex ".*index.l.* 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失败了。

If I understand your question correctly, you need grant several *nix user accounts write access to the same git repository. 如果我正确理解您的问题,您需要授予几个* nix用户帐户对同一git存储库的写访问权限。 Using the --share command line argument for git init should enable this. 使用git init--share命令行参数应启用此功能。 The GitWiki has a few words to say about this . GitWiki对此有几句话要说 This should do the trick: 这应该做的伎俩:

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

Git is meant to be distributed. Git意在分发。 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 .git directory. 除此之外,我怀疑.git目录的权限。

I would guess the ownership of the .git directory are the problem. 我猜想.git目录的所有权是个问题。

You shouldn't use one source tree from different users - it's likely to lead to problems. 您不应该使用来自不同用户的一个源树 - 这可能会导致问题。

The git executable is not the issue. git可执行文件不是问题。 It should be owned by root, and have 755 permissions. 它应该由root拥有,并拥有755个权限。 ( -rwxr-xr-x ) -rwxr-xr-x

In other words you can use git from multiple accounts, but you shouldn't share a single working directory. 换句话说,您可以使用多个帐户中的git,但不应共享一个工作目录。

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/git with a shell script that calls rm -rf $HOME .) (尝试使用调用rm -rf $HOME的shell脚本覆盖/usr/bin/git 。)

Change the permissions back to 755 and make git owned by root:root again. 将权限更改回755并再次使root用户拥有git。 (Ubuntu's package manager would reset the permissions on the next upgrade anyhow unless you used dpkg-statoverride(8) ) (除非你使用dpkg-statoverride(8)否则Ubuntu的包管理器无论如何都会重置下一次升级的权限)

I agree with those who say that it may not be a good idea to have multiple users share one git repository. 我同意那些说多个用户共享一个git存储库可能不是一个好主意的人。 If you still think that it is necessary, consider setting up a new group, chgrp the directory holding the repository and all the files therein to that group andset the setgid bit on the directories. 如果您仍然认为有必要,请考虑设置一个新组,将保存存储库的目录及其中的所有文件chgrp到该组,并在目录上设置setgid位。 (The --shared parameter to git init may do some of this for you, too.) Then, add all the users to the group that should have commit rights. git init--shared参数也可以为你做一些。)然后,将所有用户添加到应该具有提交权限的组中。

You can verify members using 您可以使用验证成员

members groupname

Then you can set the permission level for the username:groupname pair, 然后,您可以设置用户名:groupname对的权限级别,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM