[LINUX] Copy files locally on Vagrant (scp)

Copy file

The command is executed locally, not on Vagrant.

When copying from local to Vagrant

$ scp /Users/user-name/Desktop/hoge.txt vagrant@web1:/www/file/

[Syntax] scp Copy source path </ font> vagrant @ VM host name </ font>: Copy destination vagrant Path </ font>

↑↑ Now you can use the local " /Users/user-name/Desktop/hoge.txt </ font>". On Vagrant (web1 virtual machine) </ font> Copy to the " / www / file / </ font>" directory.

When copying from Vagrant to local

$ scp vagrant@web1:/www/file/hoge.txt /Users/user-name/Desktop/

See vm.hostname in the Vagrantfile for the VM host name.


Vagrant.configure("2") do |config|
  config.vm.define "default" do |web1|
    web1.vm.box = "mvbcoding/awslinux"
    web1.vm.hostname = "web1"
    web1.vm.network "private_network", ip: "xxx.xxx.xxxx"

Copy directory

With the -r option, you can scp each directory.

Copy the hoge directory onto vagrant

$ scp -r /Users/user-name/Desktop/hoge vagrant@web1:/www/file/fuga/

that's all.