Vagrant: Copy File ( To | From ) – ( Host | Guest VM ) – Vagrant SCP

Very common situation when you need to perform one-time operation of copying some file or a directory between Vagrant host and guest VM and you don’t want to waste time on mounting shared volumes or performing traditional provisioning with built-in file provisioner or some configuration management tool.

In the following article i will show the easiest way to copy files and folders between Vagrant host and guest VM using vagrant-scp plugin.

Cool Tip: Vagrant In 5 Minutes – Tutorial for Beginners! Read More →

Copy Files Between Vagrant Host and Guest VM

vagrant-scp plugin requires vagrant-vbguest, so firstly it needs to install the dependency, otherwise you may get the error as follows:

Unable to resolve dependency: user requested ‘vagrant-vbguest (= 0.15.1)’

Install vagrant-vbguest and vagrant-scp:

$ vagrant plugin install vagrant-vbguest
$ vagrant plugin install vagrant-scp

To copy a file or a directory between Vagrant host and guest VM you need to know the id or the name of a guest VM.

This information can be found in the output of the following command:

$ vagrant global-status

Copy file or directory from Vagrant host machine to guest VM:

$ vagrant scp <some_local_file_or_dir> <vm_name>:<some_path_on_vm>

Copy file or directory from guest VM to Vagrant host machine:

$ vagrant scp <vm_name>:<some_file_or_dir_on_vm> <some_local_path>