流浪者应该为每个命令都需要sudo吗



简而言之,我的问题是:每次执行任何没有"sudo"的Vagrant命令时,我都会遇到权限错误——从vagrant upvagrant provision。这是预期的行为吗?

/Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:295:in `unlink': Permission denied - /Users/Cibulka/Sites/.vagrant/machines/default/virtualbox/id (Errno::EACCES)
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:295:in `delete'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:295:in `id='
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:438:in `state'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/providers/virtualbox/action/created.rb:11:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/call.rb:43:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/providers/virtualbox/action/check_virtualbox.rb:17:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:196:in `action_raw'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:173:in `block in action'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/environment.rb:434:in `lock'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `call'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `action'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/commands/provision/command.rb:35:in `block in execute'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/plugin/v2/command.rb:226:in `block in with_target_vms'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/plugin/v2/command.rb:220:in `each'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/plugin/v2/command.rb:220:in `with_target_vms'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/commands/provision/command.rb:34:in `execute'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/cli.rb:42:in `execute'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/environment.rb:252:in `cli'
from /Applications/Vagrant/bin/../embedded/gems/gems/vagrant-1.6.3/bin/vagrant:166:in `<main>'

我在Mac OSX 10.7.5上运行。

旁注

除了上面提到的权限错误,我还收到了很多其他各种错误和超时,所以我怀疑我的Vagrant安装可能存在根本问题(可能是权限方面的问题?)。但由于我显然不是Unix忍者,我真的不确定这里的问题是什么。根据谷歌的说法,大多数错误都很常见,可能是由多种原因引起的(例如"等待机器启动时超时"或其他原因)。

最近,经过第十次试验,我成功地获得了vagrant up。我收到这个错误:通过SSH连接到机器的私钥必须由运行Vagrant的用户所有。"运行后…

sudo chown root insecure_private_key

我的流浪者似乎表现得更稳定了。

这只是为我的问题提供一些(相当本地化的)上下文的旁注,所以如果它没有提供任何值,请随意编辑/删除它。

作为自己安装脚本的一部分,我完成了第一个vagrant up,该脚本以sudo的形式运行。因此,安装的每个文件都属于root用户,而不是我的当前帐户。

相关:

  • https://github.com/Varying-Vagrant-Vagrants/VVV/issues/261
  • 非Sudo Vagrant用户的Vagrant Up失败

简而言之,当您遇到类似的问题时,您总是可以"收回"相关文件的所有权。

chown -R <USERNAME> /<YOUR-WEBSITES-DIRECTORY>/.vagrant/machines/
chown -R <USERNAME> /<YOUR-HOME-DIRECTORY>/.vagrant.d

从现在起,vagrant up和其他命令应该在没有sudo的情况下工作。

我不得不更改"/媒体";流浪者能够在此文件夹中创建虚拟机。

sudo chown -R <USERNAME>:<USERNAME> /media

之后,vagrant up按预期工作,而不需要sudo权限。

对于依赖libvirt创建虚拟机的Vagrant用户:

我找到了另一件可能的事情,以便在没有苏多的情况下流浪。但我在Ubuntu上运行它,所以不完全确定它是否适用于Mac操作系统。但我仍然对它很有信心,因为它主要是关于unix权限的。

在谷歌上搜索我的问题时,我发现了这个解释问题的Red hat文档:当你安装libvirt时,它会创建一个";libvirt";系统上的组,并声明只有该组中的人才能使用它。

所以你所要做的就是把自己加入到这个团队中。例如,在usermod可用的系统上,这将是:

sudo usermod -a -G libvirt your_username

您必须注销(或重新启动)新组才能应用于您的用户

最新更新