ruby “不要以 root 身份运行 bundler” - 使用 root 的确切区别是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25437817/
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
"Don't run bundler as root" - what is the exact difference made by using root?
提问by user56reinstatemonica8
If you run ruby bundler from the command line while logged in as root, you get the following warning:
如果您在以 root 身份登录时从命令行运行 ruby bundler,您会收到以下警告:
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
不要以 root 身份运行 Bundler。如果需要,Bundler 可以要求 sudo,并且以 root 用户身份安装你的 bundle 会破坏该机器上所有非 root 用户的应用程序。
What is this exact difference that running bundler as root makes to the gems it installs?
以 root 身份运行 bundler 对它安装的 gem 有什么确切的区别?
Is it to do with the permissions of the actual files that it installs for each gem? Will Ruby try to access the gem files as a non-root user (and if so, what user / group would Ruby use and how would I find out)?
是否与它为每个 gem 安装的实际文件的权限有关?Ruby 是否会尝试以非 root 用户身份访问 gem 文件(如果是这样,Ruby 将使用哪个用户/组以及我如何找到)?
What would be the symptoms of an application that is broken due to bundler being used as root?
由于将 bundler 用作 root 而导致应用程序损坏的症状是什么?
My specific reason for asking is because I'm trying to use bundler on a very basic Centos VPS where I have no need to set up any non-root users. I'm having other problems with gems installed via bundler(Error: file to import not found or unreadable: gemnamedespite the gem in question being present in gem list), and I'm wondering if installing the gems via bundler as root might have made the files unreadable to Ruby.
我提出这个问题的具体原因是因为我试图在一个非常基本的 Centos VPS 上使用 bundler,我不需要设置任何非 root 用户。我在通过 bundler 安装 gem 时遇到了其他问题(Error: file to import not found or unreadable: gemname尽管有问题的 gem 存在于 中gem list),我想知道以 root 身份通过 bundler 安装 gem 是否可能使文件无法被 Ruby 读取。
I want to work out if I do need to set up a non-root user account purely for running bundler, and if I do, what groups and privileges this user will need to allow Ruby to run the gems bundler installs.
我想弄清楚是否需要设置一个纯粹用于运行 bundler 的非 root 用户帐户,如果需要,该用户需要哪些组和权限才能允许 Ruby 运行 gems bundler 安装。
Or can I just chownor chgrpthe gem folders? If so, does it depend on anything to do with how Ruby is installed? (I used RVM and my gems end up in /usr/local/rvm/gems/which is owned by root in group rvm) This loosely related question's answer implies that unspecified aspects of how Ruby is installed influence bundler's permissions requirements.
或者我可以只chown或chgrpgem 文件夹?如果是这样,它是否与 Ruby 的安装方式有关?(我使用了 RVM 并且我的 gems 最终/usr/local/rvm/gems/归 rvm 组中的 root 所有)这个松散相关问题的答案意味着 Ruby 安装方式的未指定方面影响了 bundler 的权限要求。
Researching the "Don't run bundler as root" message only comes up with an unanswered questionand complaints that this warning is apparently "like it saying to go to sleep at 8PM" (link contains NSFW language).
研究“不要以 root 身份运行捆绑程序”消息只提出了一个未回答的问题和抱怨,该警告显然是“就像它说晚上 8 点睡觉”(链接包含 NSFW 语言)。
采纳答案by Pak
So I had to dig into the git log history of bundler's repo, because GitHub doesn't allow searchin git commits messages anymore.
所以我不得不深入研究 bundler 的 repo 的 git log 历史,因为 GitHub不再允许在 git commits 消息中搜索。
The commit c1b3fd165b2ec97fb254a76eaa3900bc4857a357says :
提交c1b3fd165b2ec97fb254a76eaa3900bc4857a357说:
Print warning when bundler is run by root. When a user runs bundle install with sudo bundler will print a warning, letting them know of potential consequences.
closes #2936
当 bundler 由 root 运行时打印警告。当用户使用 sudo bundler 运行 bundle install 时将打印警告,让他们知道潜在的后果。
关闭#2936
Reading this issue, you understand the real reason you should not use the rootuser:
阅读这个问题,你明白了你不应该使用root用户的真正原因:
Running sudo bundle install can cause huge and cascading problems for users trying to install gems on OS X into the system gems. We should print a warning and explain that Bundler will prompt for sudo if it's needed. We should also warn people that sudo bundle will break git gems, because they have to be writable by the user that Bundler runs as.
运行 sudo bundle install 可能会导致用户尝试将 OS X 上的 gems 安装到系统 gems 中的巨大和级联问题。我们应该打印一个警告并说明 Bundler 会在需要时提示输入 sudo。我们还应该警告人们 sudo bundle 会破坏 git gems,因为它们必须可由 Bundler 运行的用户写入。

