我正在使用Nginx服务器。我想用Vagrantfile将配置文件复制到/etc/nginx/conf.d。我使用的命令是:
config.vm.provision "file", source: "./bolt.local.conf", destination: "/etc/nginx/conf.d/bolt.local.conf"
字符串
我收到的错误是:
Failed to upload a file to the guest VM via SCP due to a permissions
error. This is normally because the SSH user doesn't have permission
to write to the destination location. Alternately, the user running
Vagrant on the host machine may not have permission to read the file.
型
我用的是bento/ubuntu-16.04盒子。
我试图寻找一种方法来改变供应命令的权限,但我只找到了改变config.vm.share_folder命令所有者的方法。
你知道答案吗?
2条答案
按热度按时间jgwigjjp1#
正如错误消息所建议的,也来自documentation:
文件提供程序以SSH或PowerShell用户的身份进行文件上传。这一点很重要,因为这些用户自己通常没有提升的权限。如果要将文件上传到需要提升权限的位置,我们建议将文件上传到临时位置,然后使用shell提供程序将它们移动到位。
因此
vagrant
用户(如果未修改)用于scp文件,但您无法使用它访问/etc/
。要使其工作,您需要将其上传到一个临时位置,然后使用shell provider将其移动到目标目录:
字符串
这是因为
privileged
选项在shell provisioners上默认为true。但是让两个provisioners只复制一个配置文件有点复杂,对吧?好吧,如果文件已经在你的共享文件夹中,你可以使用shell provider将其复制到nginx目录中,这样你就会得到这样的结果:
型
vmjh9lq92#
vagrant
用户有权访问的第一个复制文件,例如/home/vagrant
。然后把它移到你想要的地方。
字符串
这很好,因为
file provisioners
使用普通用户,而shell provisioners
使用root用户来执行作业。