如何使用 sudoers 以另一个用户身份运行 Mercurial 命令
我们所有的开发人员都可以通过 ssh 登录到我们的临时服务器。
当他们在临时服务器上运行任何 hg
命令时,他们就会成为更新/新文件的所有者。我需要这些文件由用户/组 www-data 拥有。
我尝试将 sudoers 文件编辑为此,
Cmnd_Alias WWW_DATA_CMDS = /usr/bin/svn, /usr/bin/hg
%developers ALL=(www-data) NOPASSWD: WWW_DATA_CMDS
正如您所看到的,我们的服务器上也有 SVN(我们正在从 SVN 转向 HG),并且此设置对于 SVN 来说效果很好,如果我们运行 SVN 命令,它会创建文件为 www- data
我如何获得相同的数据以用于 Mercurial?
All our developers are able to log in to our staging server via ssh.
When they run any hg
command on the staging servers it makes them the owner of the updated/new files. I need these files to be owned by the user/group www-data.
I tried editing the sudoers files to this
Cmnd_Alias WWW_DATA_CMDS = /usr/bin/svn, /usr/bin/hg
%developers ALL=(www-data) NOPASSWD: WWW_DATA_CMDS
As you can see we have SVN on the server as well (we are moving away from SVN to HG) and this setup works fine for SVN, if we run the SVN command it creates files as www-data
How do I get the same to work for Mercurial?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先要明白这里没有魔法。 Mercurial 始终以其运行用户的身份创建文件,故事结束了。它不会尝试(甚至没有权限)做任何其他事情。
这意味着,如果您仅通过 sudo 运行 hg,并且现有文件的权限正确,那么它将执行您想要的操作。
但这也意味着,如果用户在没有 sudo 的情况下运行 hg,并且他们拥有正确的权限,他们就会造成混乱。 Mercurial 满足于让您执行 Unix 权限模型允许的任何操作。
有三种方法可以解决这个问题:
内容最后的工作原理如下:
这将确保每次用户在项目,该组中的其他人都可以读/写该项目。
First understand that there's no magic here. Mercurial always creates files as the user it runs as, end of story. It doesn't try (and doesn't even have permission) to do anything else.
That means that if you run hg only via sudo, and the permissions of the existing files are right, it WILL do what you want here.
But that also means that if users run hg without sudo, and they have the right permissions, they WILL make a mess. Mercurial is content to let you do whatever is allowed by the Unix permission model.
There are three approaches to dealing with this:
This last works as follows:
This will ensure that every time a user creates a file in the project, it will be read/write for everyone else in the group.